Can you show me your database schema. If it works on one I don't know why it doesn't work on the other.
On Mar 16, 3:52 pm, maestro <mustafa...@gmail.com> wrote: > Am stumped by the same problem. I have a form that corresponds to the > main db object, and in it i have a bunch of embedded forms with > related objects. I need the ID generated for the main object to pass > to the related objects. The main object is being saved fine (I see it > in the DB), but when i try to do this 'this->getObject()-getId()' I > get back a null value. I have done the exact same thing with another > form and it is working fine. What am I doing wrong? Here is the code > in my embedded form? > > public function saveEmbeddedForms($con = null, $forms= null) > { > ....... > ....... > > foreach($receivers as $reciever){ > $msg_reciever = new MessageReciever(); > > $msg_reciever->setMessageId($this->getObject()->getId()); > > $msg_reciever->setRecieverId($reciever->getId > ()); > > $msg_reciever->setStatus($this->getObject()->getStatus()); > > $msg_reciever->save(); > } > } > > and this is how i embed the form > > $recivers_form = new MessageRecieverForm($this->getObject()); > $this->embedForm('recievers', $recievers_form); > > I don't know if this the best way to do this, but, by God, it has > worked before.. > > I hope someone can get to the bottom of this.. > cheers, > > On Mar 16, 11:38 am, lionslair <webmas...@lionslair.net.au> wrote: > > > I think that is basically same as what I have here. > > > The ServerForm > > > // ServerFormClass extends BaseServerForm > > > public function configure() > > { > > > // remove some fields from the form > > unset($this['created_at'], $this['updated_at'], $this > > ['server_key']); > > > // if ($this->isNew()) > > // { > > // unset($this['hardware_information']['server_id']); > > // } // end if > > > $maintain_options = array( > > 'Y' => 'Yes', > > 'N' => 'No', > > ); > > > $this->widgetSchema['maintain'] = new sfWidgetFormChoice > > (array('choices' => $maintain_options)); > > // $this->widgetSchema['contact_id'] = new > > sfWidgetFormInputHidden(); > > $this->widgetSchema['contact_id'] = new > > sfWidgetFormPropelChoice(array('model' => 'Contact', 'order_by' => > > array('Name', 'asc'), 'label' => 'Contact')); > > $this->widgetSchema['server_type_id'] = new > > sfWidgetFormPropelChoice(array('model' => 'ServerType', 'order_by' => > > array('Name', 'asc'), 'label' => 'Server Type', 'expanded' => true)); > > // 'default' => ServerTypePeer :: retrieveIdByName('server') > > > // echo $this->getObject()->getInstallDate("Y"); > > $years = range(date('Y') - 10, date('Y') + 15); > > > // $server_info = $this->getObject()->getServer > > > /* > > * check if the object is new > > */ > > if ($this->getObject()->isNew()) > > { > > $this->widgetSchema['install_date'] = new sfWidgetFormDate(array > > ('format' => '%day%/%month%/%year%', 'years' => array_combine($years, > > $years), 'empty_values' => array('year' => date("Y"), 'month' => date > > ('m'), 'day' => date('d')))); > > $this->widgetSchema['next_date'] = new sfWidgetFormDate(array > > ('format' => '%day%/%month%/%year%', 'years' => array_combine($years, > > $years), 'empty_values' => array('year' => date('Y'), 'month' => date > > ('m'), 'day' => date('d')))); > > // $this->widgetSchema['server_type_id']->setDefault > > (ServerTypePeer :: retrieveIdByName('server')); > > } > > else > > { > > $this->widgetSchema['install_date'] = new sfWidgetFormDate(array > > ('format' => '%day%/%month%/%year%', 'years' => array_combine($years, > > $years), 'empty_values' => array('year' => > > $this->getObject()->getInstallDate('Y'), 'month' => > > $this->getObject()->getInstallDate > > > ('m'), 'day' => $this->getObject()->getInstallDate('d')))); > > $this->widgetSchema['next_date'] = new sfWidgetFormDate(array > > ('format' => '%day%/%month%/%year%', 'years' => array_combine($years, > > $years), 'empty_values' => array('year' => > > $this->getObject()->getNextDate('Y'), 'month' => > > $this->getObject()->getNextDate('m'), > > > 'day' => $this->getObject()->getNextDate('d')))); > > } // end if else > > > $this->widgetSchema->setLabels(array('notes' => 'Comments')); > > > // only embed if there is a type object (edit vs create) > > if (!$this->getObject()->isNew()) > > { > > $this->embedForm('information', $this->getServerInfoObject()); > > // $this->embedForm('Hardware Information', new > > ServerInfoForm(ServerInfoPeer :: > > retrieveByServerId($this->getObject()->getId()))); > > > } > > else > > { > > $server_info_form = new ServerInfoForm(); > > > > $server_info_form->getObject()->setServerId($this->getObject()->getId()); > > > $this->embedForm('Hardware Information', $server_info_form); > > > unset($server_info_form['server_id']); > > } > > > // unset($this['server_id']); > > } > > > How ever when I then save this new server and new record I get the two > > records inserted and the server_id field within the server_info table > > is not getting the id (server.id) value from the server table added to > > it. > > > I have spent so much time trying to work this out. All I want is when > > the new server record is created and the embbed server_info fields are > > submitted that the server_info record that is created then uses the > > newly created server.id field that should populate the server_id field > > of the server_info table > > > It is the exact same principle as the user and user profile > > relationship. > > > On Mar 16, 12:42 am, justin_davis <jdavis1...@gmail.com> wrote: > > > > I'm doing something like this, and this is my solution: > > > > Let's say you have two forms, one is an sfGuardUser form (Form 1), the > > > other is a Profile form (Form 2) (representing those two models). > > > When a new user is created, a new profile must be also created that > > > depends on that record (Profile depends on sfGuardUser): > > > > (this is sfGuardUserForm.class.php): > > > > $profileForm = new ProfileForm(); > > > $profileForm->getObject()->setsfGuardUserId($this->getObject()); > > > $this->embedForm('profile', $profileForm); > > > > You'll also want to unset the sfGuardUserId field: unset($profileForm > > > ['sf_guard_user_id']); > > > > So, it's basically creating a ProfileForm, getting the object related > > > to it, then telling symfony to set that object's sfUserGuardId to > > > equal the sfGuardUser object that this class represents. > > > > Does that make sense? Hope this helps. I'm somewhat of a newb > > > myself, so I may be telling you something that doesn't apply. > > > > Good luck! > > > > Justin > > > > On Feb 5, 4:25 pm, Timmy <m...@timothybowler.com> wrote: > > > > > I have two forms form 1 and form 2. Form 2 is embedded into form 1. On > > > > save form1 must be saved as a new row and therefore recieving a > > > > primary key, Afterwards this foreign key needs to be injected into > > > > form 2 before it can save. > > > > > The only way i have figured out at the mo is after the form is valid. > > > > Instantiate the two models, populate them, add form2 model to form 1 > > > > model then save. > > > > > Isn't there an easier way? > > > > > Thanx > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---