jeudi 2 avril 2015

Saving belongsToMany associations in CakePHP 3


Vote count:

0




I have encountered a problem whilst saving belongsToMany associations and the data being saved is a combination of existing entities and new entities.


The data array is as follows:



$data = [
'tags' => [
['label' => 'Some new tag'],
['label' => 'Another new tag'],
'_ids' => [1, 2]
]
];


Is it that these two methods of saving this association cannot be used together?


I have tried creating a data array where each entity is its own array item like the following:



$data = [
'tags' => [
['label' => 'Some new tag'],
['label' => 'Another new tag'],
['id' => 1],
['id' => 2]
]
];


But when it is just ids this does not create new associations. Do I need to handle the creation of new entities first and then create the associations using the ['_ids'] methods, or is there something wrong with my data array?



asked 1 min ago







Saving belongsToMany associations in CakePHP 3

Aucun commentaire:

Enregistrer un commentaire