带有附加数据的 Cakephp 3 habtm

Cakephp 3 habtm with additional data

在浏览有关书签和标签的 a cakephp 3 tutorial 时,我遇到了一个问题:我想将第三个字段添加到 users_tags table (tag_type : 重要与否),但是当它保存数据时,它会将以前的值重写为默认数据库值 "tag_type".

你能帮我找出我做错了什么吗?

如果您将 tag_type 列添加到 users_tags table 之后 运行 烘焙命令,检查 $_accessible table 实体文件中的数组值,即 src/Model/Entity/UsersTag.php 并添加一个元素,其中列名作为键,true 作为值,以确保列值可以是 mass assigned

在您的 Form html of user add/edit 页面中,添加这样的输入,以便当您在控制器中创建实体时,cakephp 会自动将其值与适当的列相匹配:

echo $this->Form->input('tags.0._joinData.tag_type');