I'm curious whether this is even possible.
Basically I have two related models. I'm wondering if it's possible to save both models as a transaction, automatically populating the foreign key of the second model with the new insert id of the first.
I know that this can be done by saving the models separately, but my question is whether it can be done as one save.
Thanks!
I ended up doing this by using after/before saves and modifying the data. I passed the id around using the registry.
My Solution
//after first model save
public function _afterSave(){
Mage::unregister('id');
Mage::register('id', $this->getData('id'));
}
//before second model save
public function _beforeSave(){
if (Mage::registry('id') && !$this->getData('id')) {
$this->setData('id', Mage::registry('id'));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With