Hi,
I've some tables in my project, using many to many relationships.

Now I've tweaked the doSave() method in the form class so that it checks all
the
SelectDoubleList and save the related relations like this:
  // This method will be invoked automatically from the main Save method to
save the many-2-many relationships
  protected function doSave($con=null)
  {
    if (is_null($con))
     {
       $con = $this->getConnection();
     }

     $this->updateObject();


     // Get the values from the form
     $narrower_associated=$this->getValue('narrower');
     $related_associated = $this->getValue('related');
     $broader_associated = $this->getValue('broader');

     $concept_id=$this->getValue('id');

     // Create a new Narrower object
     $narrower = new Narrower();
     // Create a new Broader object
     $broader = new Broader();
     // Create a new Related object
     $related = new Related();

     // Associate the Concept ID
     $narrower->setConceptId($concept_id);
     $broader->setConceptId($concept_id);
     $related->setConceptId($concept_id);

     // Foreach Narrower field set the Child attribute and save
     if(sizeof($narrower_associated)>0) {
       foreach($narrower_associated as $associated) {
     $narrower->setChildConcept($associated);
      $narrower->save();
    }
   }

     // Foreach Related field set the Child attribute and save
     if(sizeof($related_associated)>0) {
      foreach($related_associated as $associated) {
      $related->setParentConcept($associated);
     $related->save();
      }
     }

     // Foreach Broader field set the Child attribute and save
     if(sizeof($broader_associated)>0) {
     foreach($broader_associated as $associated) {
      $broader->setParentConcept($associated);
     $broader->save();
     }
     }

 return parent::doSave($con);
  }


Now this save any new relation, but what about when a relation is
deleted/unassociated from the select list? How I can go through
the arrays and add the new one and delete everything else from the db?

thanks
T.

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

Reply via email to