function beforeSave($options = array()) { if (!parent::beforeSave($options)) { return false; } $this->unbindModel(array('hasAndBelongsToMany' => array('Gasto'))); // list($join) = $this->joinModel($this->hasAndBelongsToMany['Gasto']['with']); // $this->bindModel( array('hasMany' => array($join)) ); return true; }
/** * Indica la sumatoria de todos los pagos realizados para ese gasto * @param integer $id gasto_id * @return $ importe pagado */ public function importePagado($id = null) { $importePagado = 0; if (empty($id)) { $id = $this->id; } $fieldContain['recursive'] = -1; $fieldContain['contain'] = 'Egreso'; $fieldContain['conditions'] = array('Gasto.id' => $id); $coso = parent::find('first', $fieldContain); if (!empty($coso['Egreso'])) { foreach ($coso['Egreso'] as $eg) { if ($eg['AccountEgresosGasto']['gasto_id'] == $id) { $importePagado += $eg['AccountEgresosGasto']['importe']; } } } return $importePagado; }