atk4.2.1
我有这个模型:
class Model_Cargo extends Model_Table {
public $table='cargo';
function init(){
parent::init();
$this->hasOne('Alumno');
$this->hasOne('Plan');
$this->addField('fecha')->type('date');
$this->addField('fechaCreacion')->type('date');
$this->addField('fechaVencimiento')->type('date');
$this->addField('name');
$this->addField('monto')->type('money');
$this->addField('cancelado')->type('boolean')->defaultValue(false);
$this->hasMany('Abono');
$this->addExpression('abonos')->set($this->refSQL('Abono')->sum('monto'));
}
}
我想用两个字段进行数学运算 + 或 -:我实际上想用表达式 'abonos' 减去字段 'monto' 我该怎么做?
让我们这样说:
$this->addExpression('balance')->set('monto'-'abonos');
//this does not work
我也想在这些字段相等的地方添加条件......我可以这样做吗?
比如:
$this->addCondition('monto','abonos');
//this does not work