try this http://trac.symfony-project.org/ticket/6374
On Fri, Jun 5, 2009 at 7:26 AM, Raphael Guillet <[email protected]>wrote: > Hi all, > > I'm loosing my hair on this one, I have succesfully nested forms before but > this case is a bit specific. I only have this problem with Doctrine, I works > fine with Propel. > > Here is my data model: I have a parent class "Product" and 2 child class > "Book" and "Video" > the primary key of the 2 children is also the foreign key (referencing > their parent) so it does not auto increment. > > The "parent" object: > > Product: > columns: > id: > type: integer > primary: true > autoincrement: true > type: string(20) > title: string(255) > > The "child" objects: > > Book: > columns: > product_id: > type: integer > primary: true > type: string(20) > editor: string(60) > pages: integer(4) > relations: > Product: > local: product_id > foreign: id > type: one > foreignType: one > > Video: > columns: > product_id: > type: integer > primary: true > format: string(20) > editor: string(60) > length: integer > relations: > Product: > local: product_id > foreign: id > type: one > foreignType: one > > I want to nest the correct child form in the parent form, depending on the > parent type value (book or video). > > when I create a new product, my executeNew gives it a type (either book or > video) > in the ProductForm, I embed a child form depending on this type by using a > getChildForm() function I made. > $this->embedForm('child', $this->getChildForm()); > > the nesting works (the correct nested form appears) > > I overwrote the ProductForm::bind() function to add this line: > > $this->embeddedForms['child']->getObject()->setProduct($this->getObject()); > > this is supposed to link the child object (from the embedded form) to its > parent object (the main form). > > but when I save a new product, the child object is not linked to the parent > Product and I get a null primary key SQL error (Doctrine tries to save my > child object with a null product_id). > > When I update a product which already has a child form, everything works > fine... (the correct nested form appears with the data and everything is > succesfully saved) > > Any idea anyone? > > If you need more details on my code I'll post it, I didn't want to scare > people away by dumping all my code... I hope I'm just missing something > obvious... > > Thanks a lot! > > Raphael > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---
