php - Laravel 枢轴关系没有指定其中之一
问题描述
我有一个表来保存应用程序上可用的所有反应(反应)和 N 个表以与数据透视表的多对多关系与此相关。
// Post Model
public function reactions()
{
return $this->belongsToMany(Reaction::class, 'reactions_posts')
->with('reactors')->groupBy('reaction_id');
}
// Reactions Model
public function post()
{
return $this->hasMany(Post::class, 'reactions_posts');
}
public function reactors(){
return $this->hasMany(User::class, 'reactions_posts');
}
一旦 N 个模型可以Reactions
使用枢轴与模型相关联,我正在寻找一种更好的方法来关联 Post x Reaction、Event x Reaction 以及将使用相同原理关联的所有必需模型,因为这种方式会产生 Post 的一些依赖性, 事件和所有的反应模型。
解决方案
推荐阅读
- php - 卷曲 json_decode 带回“NULL”
- django - 如何在 django admin 中删除列表输入的某些元素
- java - 尝试从 Firebase 数据库中获取值并创建 if else 语句以在 firebase 中设置值,但应用程序仅执行第四行
- json - 使用 Ajax 将复杂对象传递给 MVC 中的控制器
- android - iOS 和 Android 分析查看我的应用版本安装基础
- network-printers - 按 IP 地址查找打印队列名称
- angular - 加入 2 个可观察的流,但具有不同的访问器
- amazon-web-services - AWS CDK:是否可以在没有 VPC.fromLookup() 的情况下将 EC2 实例或 SG 创建到默认 VPC 中?
- python - 为什么当值通过条件时我的while循环仍然运行
- sql-server - 是否可以运行一个while循环来创建动态选择列