Sunday, February 22, 2015

Re: Still having trouble with saving BelongsToMany data

If Listings is the table being saved, having attributes, then there seems to be something wrong with your data.
I believe that your data should look like the following:


$data = [
    'attributes' => [
        [
            'id' => 3,  //provided the id is already known
            '_joinData' => [
                'value' => 'Off-street'
            ]
        ],
    ]
];
$listing = $this->Listings->newEntity($data, [
    'associated' => ['Attributes._joinData']
]);

Question: Did you try baking the models, making sure the associations were all correct as as you expected, then bake the controllers and views?  It seems that the bake utility should generate the code for doing this.
--Kevin

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: