On 25 abr, 12:28, sucram <[EMAIL PROTECTED]> wrote:
> Hi there!
>
> I know, I know ... search this group an u will find the solution ...
> Well, I searched, but I didn't find ...
> So, maybe u can help me ...
>
> I try to use hasAndBelongsToMany association but I'm stuck with saving
> the data ...
>
> I've got three tables ...
>
> * locations: id, ...
> * staffs: id, ...
> * locations_staffs: location_id, staff_id
>
> Staff Model:
> class Staff extends AppModel {
>         var $name = 'Staff';
>         var $hasAndBelongsToMany = array('Location');
>
> }
>
> Location Model:
> class Location extends AppModel {
>         var $name = 'Location';
>         var $hasAndBelongsToMany = array('Staff');
>
> }
>
> Staff Controller:
> function add()
> {
>         $this->set('locations',$this->Staff->Location->generateList());
>                 if(!empty($this->data)){
>                 $this->Staff->save($this->data);
>                 pr($this->data);
>         }
>
> }
>
> Output of pr()
>
> Array
> (
>     [Location] => Array
>         (
>             [Location] => Array
>                 (
>                     [0] => 2
>                 )
>         )
>
>     [Staff] => Array
>         (
>             [section] => sadfsdaf
>             [firstname] => sdfsdf
>             [lastname] => sdfsdf
>             [email] => sdfsdf
>             [phone] => sdfsdf
>         )
> )
>
> I tried scaffolding and it works, so i think my naming of tables etc.
> is correct.
>
> Any ideas, why the  locations_staffs table still stays empty when I
> save manualy?
>
> Regards,
> Marcus

Change the order of your fields in the form, Staff needs to be the
first array key (iirc). if you don't want to change the order of your
fields, just add a hidden field for anything that is related to the
Staff before the selectbox (which will have the same effect).

hth,

AD
PS. only a suggestion based on a vague memory of that sort of thing.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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