【发布时间】:2018-11-24 18:51:36
【问题描述】:
我是 cakephp 新手,我正在关注教程,我来自其他语言,我不习惯阅读这样的查询:
public function findTagged(Query $query, array $options)
{
$columns = [
'Articles.id', 'Articles.user_id', 'Articles.title',
'Articles.body', 'Articles.published', 'Articles.created',
'Articles.slug',
];
$query = $query
->select($columns)
->distinct($columns);
if (empty($options['tags'])) {
// If there are no tags provided, find articles that have no tags.
$query->leftJoinWith('Tags')
->where(['Tags.title IS' => null]);
} else {
// Find articles that have one or more of the provided tags.
$query->innerJoinWith('Tags')
->where(['Tags.title IN' => $options['tags']]);
}
return $query->group(['Articles.id']);
}
这是一个简单的查询,很容易理解,但是如果我有一个更复杂的查询,有很多连接等,有没有可能用 sql sintax 编写自己的查询,你能帮我把这段代码翻译成用sql写的查询?
谢谢
【问题讨论】:
标签: mysql cakephp-3.0