Hi,

How to add an item to a HABTM relation ?

I have a Person and I have to add a Contract to that person.
Here are the data on a view :

data[Contract][type] : 12
data[Contract][name] : contract-AAaa
data[Contract][Person] : 26 // Should I put the person id here ?? or  
something else ??

In fact, that contract added to person 26 could be later on added to  
another Person, that's why its HABTM.
Currently, I'm trying to add a new contract to an existing person, so  
the question, but later I'm not sure how to just link an existing  
contract to an existing person ...

Here is the code on the controller to receive that data :
     function add() {
         if (!empty($this->data)) {
                        $this-> Contract->create();
                        if ($this-> Contract->save($this->data)) {
                            $this->set('returncode', 'Contract '.$this-> 
Contract->id.'  
saved');
                        } else {
                                $this->set('returncode', 'ERROR : Contract 
'.$this- 
 >data['Contract']['name'].' not saved');
                        }
         }
     }

Thanks !

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to