saveAll HABTM没有全部保存

时间:2015-05-09 23:18:22

标签: php cakephp cakephp-2.3

我的模特中都有HABTM关系。

Person.php

public $hasAndBelongsToMany = array(
    'Tag' =>
        array(
  'className' => 'Api.Tag'
));

Tag.php

public $hasAndBelongsToMany = array(
    'Person' =>
        array(
        'className' => 'Api.Person',

    ));

PeopleController.php

public function edit(){
    $results = $this->Person->saveAll($this->request->data);
}

_

(
[id] => 554d92e1-7920-409a-b348-080e2773a233
[firstname] => George
[lastname] => Jones
[Company] => Array
    (
        [id] => 554995a3-f880-4a02-b971-9ac82773a233
        [title] => xxxx
    )

[Tag] => Array
    (
        [0] => Array //this is an existing tag
            (
                [id] => 530e487c-44bc-4ffe-ae2b-152f4056922c
                [title] => monkey
                [PeopleTag] => Array
                    (
                        [id] => 554e741d-a98c-48d0-8a52-080c2773a233
                        [tag_id] => 530e487c-44bc-4ffe-ae2b-152f4056922c
                        [person_id] => 554d92e1-7920-409a-b348-080e2773a233
                        [created] => -62169987600
                        [modified] => 1431207117
                    )
            )

        [1] => Array //this is a new tag that's not being added
            (
                [title] => rocketship
            )

        [2] => Array //this is a new tag that's not being added
            (
                [title] => houses
            )

    )

)

当我在数据库中手动设置标签时,我能够正确地将它们读回我的应用程序,当我删除现有标签时,它们会从数据库中删除。问题是当我尝试使用cakephp添加它们时没有添加任何内容。

我的数据阵列看起来有点时髦,因为我实际上正在使用这个插件来改变事物。 http://friendsofcake.com/crud/docs/listeners/api-transformation.html

我的CakePHP应用程序正在获取下面的数据,但它不是添加我的新标签,也不是在people_tags连接表中添加我的关联。对我做错了什么的想法?

0 个答案:

没有答案