- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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 |
--------------------------
| | | |
--------------------------
我已将发布请求数据显示在 Controller 中:
Array
(
[id] => 1
[xyz] => blahblah
[apples] => Array
(
[_ids] => Array
(
[0] => 1
)
)
[amount] => 15000
)
现在,当我执行save
时,只有 Baskets 表得到更新,join 表保持不变,并且不会抛出任何错误。
我知道我肯定遗漏了一些东西,但无法弄清楚。请帮忙!!!
最佳答案
尝试检查您的 Baskets
实体类是否使其 apples
属性 _accessible
:
<?php
namespace app\Model\Entity;
use Cake\ORM\Entity;
class Basket extends Entity {
public $_accessible = [
'apples', // <-- make sure this is present
];
}
在使用这些新的实体类尝试加载数据时(使用 Table::newEntity()
或 Table::patchEntity()
),一个很常见的陷阱),但由于批量分配保护,其中一些数据实际上并未保存到实体中。
引用:http://book.cakephp.org/3.0/en/orm/entities.html#mass-assignment
关于php - Cake 3.0如何保存belongsToMany数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32105778/
我有两个模型:用户和经济事件。它们通过 UserEconomicActivity 关联(这是一个 BelongsToMany 关系)。在 User 模型中,我定义了这样的关联: this.belong
考虑下表: user id name client id name user_client user_id client_id rate ... 我希望我的 Contr
给定以下 belongsToMany 关系: 标签模型: class Tag extends Model { public function posts (){ return
假设我有以下模型: const Item = sequelize.define("Item", { active: { type: DataTypes.BOOLEAN, defaultValu
我使用了 Sequelize 并使用 belongsToMany() 设置了多对多关系。但是,当我查询出数据时,像这样: api.models.operator.find({ where:
在Laravel中定义多对多关系时,使用belongsToMany()或hasManyThrough()有什么区别? 例:UserAccountAccount_User 因此,用户通过Account_
我有两个带有数据透视表的表(用户和饮料),用户与配置文件表有 hasOne 关系,有没有办法将配置文件表附加到数据透视表并获取所有数据。 表格用户 id | name | email 表格配置文件 i
我有两个带有数据透视表的表(用户和饮料),用户与配置文件表有 hasOne 关系,有没有办法将配置文件表附加到数据透视表并获取所有数据。 表格用户 id | name | email 表格配置文件 i
我有两个表具有 belongsToMany 关系。数据透视表还包含一个名为 state 的列,它可以有 3 个不同的值。假设我的表是 Table1 和 Table2。 具有不同状态的相同Table1-
所以我有一个名为 thread_user 的数据透视表,并且有两个模型; User.php 和 Thread.php。 我的 User.php 文件中有这个: public function thre
我在 PostgreSQL 上使用 Sequelize 来存储属于组织的用户。组织拥有用户可以访问的设备。因此,从本质上讲,用户也通过他们的组织拥有设备。 我将其设置为每个设备都使用 organiza
我正在 Laravel 中实现多对多关系。这些实体是:用户角色和数据透视表 user_role Users ==== id name ..... roles ==== id role ... u
我试图建立多对多的关系,在这个例子中是用户和角色。 在用户模型中我得到了这个: public function roles() { return $this->belongsToMany('A
我有如下三个表: 用户 id|名称|用户名|密码 角色 编号|名称 用户角色 id|user_id|role_id 这些表通过 belongsToMany 进行通信。我想找到一种方法来选择“users
我的项目中有 belongsToMany 关系: 公共(public)函数产品() { 返回 $this->belongsToMany(Product::class,'order_products',
我有以下模型。 class Training extends \Eloquent { // Add your validation rules here public static $
所以我通过数据透视表 user_photo 在 Users 和 Photos 之间建立了多对多关系。我在我的用户模型中使用 belongsToMany('Photo')。然而,这里的问题是我的照片表中
我有这个给定的表结构: 如何使用 Eloquent 从我的“visita”类访问“curso.name”?我分配了多对多关系,但只能访问“turma.curso_id”,但我想得到类似 $visita
使用 sequelize,我期望这一行: m.User.belongsToMany(m.Company, {through: 'UserCompany'}); 在我的数据库中生成一个名为“user_c
我有两个表:categories 和 videos,然后我有一个数据透视表,因为它们是 belongsToMany 关系。 我想要做的是获取所有视频,其中没有一个视频实例属于多个类别之一。 例如 视频
我是一名优秀的程序员,十分优秀!