[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread maestro


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.

 

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread lionslair

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);

        

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread maestro

Am still on it.. here is my schema.


message:
_attributes: { phpName: Message }
id:
sender_id:
subject:
body:
status_id:
created_at:

message_reciever:
_attributes: { phpName: MessageReciever }
id: { type: BIGINT, primaryKey: true, required: true }
message_id: { type: BIGINT, required: true, foreignTable: message,
foreignReference: id }
reciever_id: { type: BIGINT, autoIncrement: true, required: true,
foreignTable: member, foreignReference: id }
status_id: { type: BIGINT, autoIncrement: true, required: true,
foreignTable: status, foreignReference: id }





On Mar 16, 4:48 pm, lionslair webmas...@lionslair.net.au wrote:
 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' = 
  

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread lionslair

These are the import functin out of the sfFormPropel.class.php

See how the main object is saved then it deals with the childs. It
works fine when the child exists but I don't know why it is not making
the  connection on the creation of new records that are made at the
same timer as main.


349
350   /**
351* Updates and saves the current object.
352*
353* If you want to add some logic before saving or save other
associated objects,
354* this is the method to override.
355*
356* @param PropelPDO $con An optional PropelPDO object
357*/
358   protected function doSave($con = null)
359   {
360 if (is_null($con))
361 {
362   $con = $this-getConnection();
363 }
364
365 $this-updateObject();
366
367 $this-object-save($con);
368
369 // embedded forms
370 $this-saveEmbeddedForms($con);
371   }
372
373   /**
374* Saves embedded form objects.
375*
376* @param PropelPDO $con   An optional PropelPDO object
377* @param array $forms An array of forms
378*/
379   public function saveEmbeddedForms($con = null, $forms = null)
380   {
381 if (is_null($con))
382 {
383   $con = $this-getConnection();
384 }
385
386 if (is_null($forms))
387 {
388   $forms = $this-embeddedForms;
389 }
390
391 foreach ($forms as $form)
392 {
393   if ($form instanceof sfFormPropel)
394   {
395 $form-saveEmbeddedForms($con);
396 $form-getObject()-save($con);
397   }
398   else
399   {
400 $this-saveEmbeddedForms($con, $form-getEmbeddedForms
());
401   }
402 }
403   }


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';
        

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread lionslair

Here is my schema.  I always generate an XML schema but converted this
so I can show you.

Can you see anything wrong with it?



propel:
  _attributes:
package: lib.model
defaultIdMethod: native
  contact:
_attributes: { phpName: Contact }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
name: { type: VARCHAR, size: '50', required: false }
phone: { type: VARCHAR, size: '50', required: false }
mobile: { type: VARCHAR, size: '50', required: false }
email: { type: VARCHAR, size: '150', required: false }
notes: { type: CLOB, required: false }
  server:
_attributes: { phpName: Server }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
contact_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0' }
company_name: { type: VARCHAR, size: '150', required: false }
ip: { type: VARCHAR, size: '50', required: false }
install_date: { type: TIMESTAMP, required: false }
next_date: { type: TIMESTAMP, required: false }
website: { type: VARCHAR, size: '150', required: false }
server_name: { type: VARCHAR, size: '150', required: false }
dyndns: { type: VARCHAR, size: '255', required: false }
maintain: { type: CHAR, size: '1', required: true, defaultValue:
'N' }
notes: { type: CLOB, required: false }
server_key: { type: VARCHAR, size: '40', required: false }
server_type_id: { type: INTEGER, size: '11', required: false,
defaultValue: '0', foreignTable: server_type, foreignReference: id }
_indexes: { contact_id: [contact_id] }
_uniques: { server_key: [server_key] }
  server_history:
_attributes: { phpName: ServerHistory }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
server_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0', foreignTable: server, foreignReference: id }
staff_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0', foreignTable: staff, foreignReference: id }
history_date: { type: DATE, required: true, defaultValue:
'-00-00' }
notes: { type: CLOB, required: false }
history_time: { type: TIME, required: true, defaultValue:
'01:00:00' }
_indexes: { server_id: [server_id], staff_id: [staff_id] }
  server_info:
_attributes: { phpName: ServerInfo }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
server_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0', foreignTable: server, foreignReference: id,
onDelete: cascade }
mainboard: { type: VARCHAR, size: '250', required: false }
cpu: { type: VARCHAR, size: '150', required: false }
memory: { type: VARCHAR, size: '150', required: false }
video: { type: VARCHAR, size: '150', required: false }
network: { type: VARCHAR, size: '150', required: false }
notes: { type: CLOB, required: false }
_indexes: { server_id: [server_id] }
  server_info_harddisk:
_attributes: { phpName: ServerInfoHarddisk }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
size: { type: VARCHAR, size: '50', required: false }
server_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0', foreignTable: server, foreignReference: id,
onDelete: cascade }
server_info_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0', foreignTable: server_info, foreignReference: id,
onDelete: cascade }
order_at: { type: INTEGER, size: '11', required: false,
defaultValue: '1' }
_indexes: { server_id: [server_id], server_info_id:
[server_info_id], order_at: [order_at] }
  server_os_type:
_attributes: { phpName: ServerOsType }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
title: { type: VARCHAR, size: '150', required: false }
  server_os_type_version:
_attributes: { phpName: ServerOsTypeVersion }
id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement:
true, required: true }
created_at: { type: TIMESTAMP, required: false }
updated_at: { type: TIMESTAMP, required: false }
server_os_type_id: { type: INTEGER, size: '11', required: true,
defaultValue: '0', foreignTable: server_os_type, foreignReference: id,
onDelete: cascade }
title: { type: 

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread lionslair

Maybe the schemas need to be done like this as I have just re-read in
the documentation.

Listing 8-28 - Foreign Key Alternative Syntax

propel:
  blog_article:
id:
title:   varchar(50)
user_id: { type: integer }
_foreignKeys:
  -
foreignTable: blog_user
onDelete: cascade
references:
  - { local: user_id, foreign: id }

The alternative syntax is useful for multiple-reference foreign keys
and to give foreign keys a name, as shown in Listing 8-29.

Listing 8-29 - Foreign Key Alternative Syntax Applied to Multiple
Reference Foreign Key

_foreignKeys:
  my_foreign_key:
foreignTable:  db_user
onDelete:  cascade
references:
  - { local: user_id, foreign: id }
  - { local: post_id, foreign: id }


On Mar 16, 6:03 pm, maestro mustafa...@gmail.com wrote:
 Am still on it.. here is my schema.
 

 message:
     _attributes: { phpName: Message }
     id:
     sender_id:
     subject:
     body:
     status_id:
     created_at:

 message_reciever:
     _attributes: { phpName: MessageReciever }
     id: { type: BIGINT, primaryKey: true, required: true }
     message_id: { type: BIGINT, required: true, foreignTable: message,
 foreignReference: id }
     reciever_id: { type: BIGINT, autoIncrement: true, required: true,
 foreignTable: member, foreignReference: id }
     status_id: { type: BIGINT, autoIncrement: true, required: true,
 foreignTable: status, foreignReference: id }
 

 On Mar 16, 4:48 pm, lionslair webmas...@lionslair.net.au wrote:

  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';
      

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread maestro

Still stuck!

Looking a the sfPropelForm save() it is clear that the call to
saveEmbeddedForms comes after the main object is getting saved. I see
it also happening in the log file. Could it be something to do with
the begin and transaction calls that surrounding doSave and
saveEmbeddedForms? I mean, maybe the id of the main object isn't
available until the db transaction gets committed. But, then am doing
the exact same thing else where and it is working fine.

hmm, need to take a break..





On Mar 16, 7:10 pm, lionslair webmas...@lionslair.net.au wrote:
 I finally cracked in.  These two functions in my ServerForm class

   public function bind(array $taintedValues = null, array
 $taintedFiles = null)
   {
     $ret = parent::bind($taintedValues, $taintedFiles);
     foreach ($this-embeddedForms as $name = $form) {
       $this-embeddedForms[$name]-isBound = true;
       $this-embeddedForms[$name]-values = $this-values[$name];
     }

     return $ret;
   }

   public function saveEmbeddedForms($con = null, $forms = null)
   {
     foreach($this-getEmbeddedForms() as $closeForm)
     {

       $entry=$closeForm-save();
       $entry-setServerId($this-getObject()-getId());
       //        mail('nat...@lionslair.net.au', 'debug', print_r
 ($entry, true));
       $entry-save();
     }
   }

 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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread Nathan Rzepecki
It is this line here that does it.

$entry-setServerId($this-getObject()-getId());

within

 public function saveEmbeddedForms($con = null, $forms = null)

Because by the time that is called the main object is then saved.


-
Nathan Rzepecki
http://www.lionslair.net.au



maestro wrote:
 Still stuck!

 Looking a the sfPropelForm save() it is clear that the call to
 saveEmbeddedForms comes after the main object is getting saved. I see
 it also happening in the log file. Could it be something to do with
 the begin and transaction calls that surrounding doSave and
 saveEmbeddedForms? I mean, maybe the id of the main object isn't
 available until the db transaction gets committed. But, then am doing
 the exact same thing else where and it is working fine.

 hmm, need to take a break..





 On Mar 16, 7:10 pm, lionslair webmas...@lionslair.net.au wrote:
   
 I finally cracked in.  These two functions in my ServerForm class

   public function bind(array $taintedValues = null, array
 $taintedFiles = null)
   {
 $ret = parent::bind($taintedValues, $taintedFiles);
 foreach ($this-embeddedForms as $name = $form) {
   $this-embeddedForms[$name]-isBound = true;
   $this-embeddedForms[$name]-values = $this-values[$name];
 }

 return $ret;
   }

   public function saveEmbeddedForms($con = null, $forms = null)
   {
 foreach($this-getEmbeddedForms() as $closeForm)
 {

   $entry=$closeForm-save();
   $entry-setServerId($this-getObject()-getId());
   //mail('nat...@lionslair.net.au', 'debug', print_r
 ($entry, true));
   $entry-save();
 }
   }

 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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread maestro

sadly $this-getObject()-getId() is returning a null in my case...
although the rest of the object values are there.

On Mar 16, 8:13 pm, Nathan Rzepecki webmas...@lionslair.net.au
wrote:
 It is this line here that does it.

 $entry-setServerId($this-getObject()-getId());

 within

  public function saveEmbeddedForms($con = null, $forms = null)

 Because by the time that is called the main object is then saved.

 -
 Nathan Rzepeckihttp://www.lionslair.net.au

 maestro wrote:
  Still stuck!

  Looking a the sfPropelForm save() it is clear that the call to
  saveEmbeddedForms comes after the main object is getting saved. I see
  it also happening in the log file. Could it be something to do with
  the begin and transaction calls that surrounding doSave and
  saveEmbeddedForms? I mean, maybe the id of the main object isn't
  available until the db transaction gets committed. But, then am doing
  the exact same thing else where and it is working fine.

  hmm, need to take a break..

  On Mar 16, 7:10 pm, lionslair webmas...@lionslair.net.au wrote:

  I finally cracked in.  These two functions in my ServerForm class

    public function bind(array $taintedValues = null, array
  $taintedFiles = null)
    {
      $ret = parent::bind($taintedValues, $taintedFiles);
      foreach ($this-embeddedForms as $name = $form) {
        $this-embeddedForms[$name]-isBound = true;
        $this-embeddedForms[$name]-values = $this-values[$name];
      }

      return $ret;
    }

    public function saveEmbeddedForms($con = null, $forms = null)
    {
      foreach($this-getEmbeddedForms() as $closeForm)
      {

        $entry=$closeForm-save();
        $entry-setServerId($this-getObject()-getId());
        //        mail('nat...@lionslair.net.au', 'debug', print_r
  ($entry, true));
        $entry-save();
      }
    }

  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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread maestro

but it is! it is right there in the db.. isn't this interesting!

On Mar 16, 10:29 pm, Nathan Rzepecki webmas...@lionslair.net.au
wrote:
 That means it is not yet saved.

 -
 Nathan Rzepeckihttp://www.lionslair.net.au

 maestro wrote:
  sadly $this-getObject()-getId() is returning a null in my case...
  although the rest of the object values are there.

  On Mar 16, 8:13 pm, Nathan Rzepecki webmas...@lionslair.net.au
  wrote:

  It is this line here that does it.

  $entry-setServerId($this-getObject()-getId());

  within

   public function saveEmbeddedForms($con = null, $forms = null)

  Because by the time that is called the main object is then saved.

  -
  Nathan Rzepeckihttp://www.lionslair.net.au

  maestro wrote:

  Still stuck!

  Looking a the sfPropelForm save() it is clear that the call to
  saveEmbeddedForms comes after the main object is getting saved. I see
  it also happening in the log file. Could it be something to do with
  the begin and transaction calls that surrounding doSave and
  saveEmbeddedForms? I mean, maybe the id of the main object isn't
  available until the db transaction gets committed. But, then am doing
  the exact same thing else where and it is working fine.

  hmm, need to take a break..

  On Mar 16, 7:10 pm, lionslair webmas...@lionslair.net.au wrote:

  I finally cracked in.  These two functions in my ServerForm class

    public function bind(array $taintedValues = null, array
  $taintedFiles = null)
    {
      $ret = parent::bind($taintedValues, $taintedFiles);
      foreach ($this-embeddedForms as $name = $form) {
        $this-embeddedForms[$name]-isBound = true;
        $this-embeddedForms[$name]-values = $this-values[$name];
      }

      return $ret;
    }

    public function saveEmbeddedForms($con = null, $forms = null)
    {
      foreach($this-getEmbeddedForms() as $closeForm)
      {

        $entry=$closeForm-save();
        $entry-setServerId($this-getObject()-getId());
        //        mail('nat...@lionslair.net.au', 'debug', print_r
  ($entry, true));
        $entry-save();
      }
    }

  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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread maestro

Oppps, this is embarrassing. I was missing the autoIncrement: true, in
my message schema.yml.
Nathan thanx for your time..

On Mar 16, 10:53 pm, maestro mustafa...@gmail.com wrote:
 but it is! it is right there in the db.. isn't this interesting!

 On Mar 16, 10:29 pm, Nathan Rzepecki webmas...@lionslair.net.au
 wrote:

  That means it is not yet saved.

  -
  Nathan Rzepeckihttp://www.lionslair.net.au

  maestro wrote:
   sadly $this-getObject()-getId() is returning a null in my case...
   although the rest of the object values are there.

   On Mar 16, 8:13 pm, Nathan Rzepecki webmas...@lionslair.net.au
   wrote:

   It is this line here that does it.

   $entry-setServerId($this-getObject()-getId());

   within

    public function saveEmbeddedForms($con = null, $forms = null)

   Because by the time that is called the main object is then saved.

   -
   Nathan Rzepeckihttp://www.lionslair.net.au

   maestro wrote:

   Still stuck!

   Looking a the sfPropelForm save() it is clear that the call to
   saveEmbeddedForms comes after the main object is getting saved. I see
   it also happening in the log file. Could it be something to do with
   the begin and transaction calls that surrounding doSave and
   saveEmbeddedForms? I mean, maybe the id of the main object isn't
   available until the db transaction gets committed. But, then am doing
   the exact same thing else where and it is working fine.

   hmm, need to take a break..

   On Mar 16, 7:10 pm, lionslair webmas...@lionslair.net.au wrote:

   I finally cracked in.  These two functions in my ServerForm class

     public function bind(array $taintedValues = null, array
   $taintedFiles = null)
     {
       $ret = parent::bind($taintedValues, $taintedFiles);
       foreach ($this-embeddedForms as $name = $form) {
         $this-embeddedForms[$name]-isBound = true;
         $this-embeddedForms[$name]-values = $this-values[$name];
       }

       return $ret;
     }

     public function saveEmbeddedForms($con = null, $forms = null)
     {
       foreach($this-getEmbeddedForms() as $closeForm)
       {

         $entry=$closeForm-save();
         $entry-setServerId($this-getObject()-getId());
         //        mail('nat...@lionslair.net.au', 'debug', print_r
   ($entry, true));
         $entry-save();
       }
     }

   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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-16 Thread Nathan Rzepecki
No problem.

-
Nathan Rzepecki
http://www.lionslair.net.au



maestro wrote:
 Oppps, this is embarrassing. I was missing the autoIncrement: true, in
 my message schema.yml.
 Nathan thanx for your time..

 On Mar 16, 10:53 pm, maestro mustafa...@gmail.com wrote:
   
 but it is! it is right there in the db.. isn't this interesting!

 On Mar 16, 10:29 pm, Nathan Rzepecki webmas...@lionslair.net.au
 wrote:

 
 That means it is not yet saved.
   
 -
 Nathan Rzepeckihttp://www.lionslair.net.au
   
 maestro wrote:
   
 sadly $this-getObject()-getId() is returning a null in my case...
 although the rest of the object values are there.
 
 On Mar 16, 8:13 pm, Nathan Rzepecki webmas...@lionslair.net.au
 wrote:
 
 It is this line here that does it.
   
 $entry-setServerId($this-getObject()-getId());
   
 within
   
  public function saveEmbeddedForms($con = null, $forms = null)
   
 Because by the time that is called the main object is then saved.
   
 -
 Nathan Rzepeckihttp://www.lionslair.net.au
   
 maestro wrote:
   
 Still stuck!
 
 Looking a the sfPropelForm save() it is clear that the call to
 saveEmbeddedForms comes after the main object is getting saved. I see
 it also happening in the log file. Could it be something to do with
 the begin and transaction calls that surrounding doSave and
 saveEmbeddedForms? I mean, maybe the id of the main object isn't
 available until the db transaction gets committed. But, then am doing
 the exact same thing else where and it is working fine.
 
 hmm, need to take a break..
 
 On Mar 16, 7:10 pm, lionslair webmas...@lionslair.net.au wrote:
 
 I finally cracked in.  These two functions in my ServerForm class
   
   public function bind(array $taintedValues = null, array
 $taintedFiles = null)
   {
 $ret = parent::bind($taintedValues, $taintedFiles);
 foreach ($this-embeddedForms as $name = $form) {
   $this-embeddedForms[$name]-isBound = true;
   $this-embeddedForms[$name]-values = $this-values[$name];
 }
   
 return $ret;
   }
   
   public function saveEmbeddedForms($con = null, $forms = null)
   {
 foreach($this-getEmbeddedForms() as $closeForm)
 {
   
   $entry=$closeForm-save();
   $entry-setServerId($this-getObject()-getId());
   //mail('nat...@lionslair.net.au', 'debug', print_r
 ($entry, true));
   $entry-save();
 }
   }
   
 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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-15 Thread lionslair

Did either of you find a solution to how to make this work?

On Feb 6, 6:25 am, 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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-15 Thread justin_davis

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
-~--~~~~--~~--~--~---



[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-15 Thread lionslair

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 

[symfony-users] Re: Save an embedded form that relies on the other form

2009-03-07 Thread saturn1...@hotmail.com

i have the same problem!!
What is the good way? plz

On 5 fév, 22:25, 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
-~--~~~~--~~--~--~---