I've this schema.yml:
SdrivingMaquina:
connection: doctrine
tableName: sdriving_maquina
actAs: [Timestampable]
columns:
idmaquina: { type: integer(8), fixed: false, unsigned: false, primary: true, autoincrement: true }
idempresa: { type: integer(4), fixed: false, unsigned: true, primary: true, autoincrement: false }
patente: { type: string(12), fixed: false, unsigned: false, primary: false, notnull: true, autoincrement: false }
relations:
Empresa: { local: idempresa, class: SdrivingEmpresa, type: one, foreignType: one, foreignAlias: MaquinaEmpresa, onDelete: CASCADE, onUpdate: CASCADE }
SdrivingMaquinaEmisor:
connection: doctrine
tableName: sdriving_maquina_emisor
actAs: [Timestampable]
columns:
idmaquinaemisor: { type: integer(8), fixed: false, unsigned: false, primary: true, autoincrement: true }
idmaquina: { type: integer(8), fixed: false, unsigned: false, primary: true, autoincrement: false }
idemisor: { type: integer(8), fixed: false, unsigned: false, primary: true, autoincrement: false }
relations:
SdrivingEmisor: { onDelete: CASCADE, local: idemisor, foreign: idemisor, type: one }
SdrivingMaquina: { onDelete: CASCADE, local: idmaquina, foreign: idmaquina, type: one }
And this is the configure()
method for the form associated:
public function configure() {
$this->current_user = sfContext::getInstance()->getUser()->getGuardUser();
unset($this['updated_at'], $this['created_at']);
$this->widgetSchema['idempresa'] = new sfWidgetFormInputHidden();
$id_empresa = $this->current_user->getSfGuardUserProfile()->getIdempresa();
$this->setDefault('idempresa', $id_empresa);
$this->widgetSchema['no_emisor'] = new sfWidgetFormDoctrineChoice(array('model' => 'SdrivingEmisor', 'add_empty' => 'Seleccione un Emisor', 'table_method' => 'fillChoice'));
$this->validatorSchema['idempresa'] = new sfValidatorPass();
$this->validatorSchema['no_emisor'] = new sfValidatorPass();
}
I'm trying after save the main maquina
then save the data for the relation SdrivingMaquinaEmisor()
but don't know and didn't find (after some Google and Stackoverflow research) the proper way to get the latest ID of SdrivingMaquina
object.
This is what I'm doing in my save()
method (in the same Form):
public function save($con = null) {
$new_machine = parent::save($con);
$relation = new SdrivingMaquinaEmisor();
$relation->setIdmaquina($new_machine->getIdmaquina());
$relation->setIdemisor($this->values['no_emisor']);
$relation->save();
return $new_machine;
}
But setIdmaquina()
never gets a value so it breaks my application and cause a CONSTRAINT error, can any point me in the right direction?