web-services - 如何在 MySql 的单个名称列中添加多个表 id 并在 CakePHP 中使用 type_id 加入?
问题描述
我的问题出在我在CakePHP中的REST API中,用于最喜欢的 API。我有多个表,例如、和,以及一个表。我只想使用表中的单个字段和一个,例如 1 代表2 代表3 代表...quotes
video
audio
favourite
fav_id
favourite
fav_type
quote
video
audio
如何fav_type
在 CakePHP 中加入单个表?
解决方案
在 QuotesTable 的初始化函数中:
$this->hasMany('Favourites', [
'foreignKey' => 'fav_id',
'className' => 'Favourite',
'dependent' => true,
// Better to define a constant for this 1 somewhere
'conditions' => ['fav_type' => 1],
]);
现在,当您get
报价时,您可以->contain(['Favourites'])
.
推荐阅读
- html - chrome mobile上的html5视频-本机播放器控制栏缺少图标(选项)
- javascript - Moment JS 日期到 C# 日期
- ruby-on-rails - Spree Commerce 分类单元中的产品数量 | Ruby on Rails
- asp.net-core - 如何创建一个继承自标准 .Net Core 脚本标签助手的脚本标签助手
- python-2.7 - Euler #4 最大回文数,python 2
- javascript - 根据道具名称映射数组,ReactJS
- java - Java Swing:如何制作其中可能有按钮的项目的可滚动视图?
- javascript - CSS类遍历DOM。语法错误?
- linux - 如何用引号替换单词和使用sed的引号之间的文本?
- wordpress - 如何在 codeigniter 中的段落之间添加 Google Adsense