【发布时间】:2015-08-19 21:14:48
【问题描述】:
我是 cakephp 新手。 http://book.cakephp.org/3.0/en/orm/associations.html#belongstomany-associations 和 http://book.cakephp.org/3.0/en/orm/saving-data.html#saving-with-associations 上的文档对于像我这样的初学者来说似乎太简短或太高级了。
据我所知,我做了以下事情。
//Table Baskets belongsToMany Apples
//At BasketsTable.php in initialize()
$this->belongsToMany('Apples',[
'joinTable' => 'apples_baskets'
]);
MySQL 中的连接表apples_baskets:
+---+---------+----------+
|id |apple_id |basket_id |
--------------------------
| | | |
--------------------------
我已将发布请求数据显示在控制器上:
Array
(
[id] => 1
[xyz] => blahblah
[apples] => Array
(
[_ids] => Array
(
[0] => 1
)
)
[amount] => 15000
)
现在当我执行save 时,只有 Baskets 表被更新,连接表保持不变,并且没有抛出错误。
我知道我肯定错过了一些东西,但无法弄清楚。请帮忙!!!
【问题讨论】:
标签: php cakephp has-and-belongs-to-many cakephp-3.0