正如标题所说,我在查找查询中遇到了连接问题,错误如下所示:
preg_match() expects parameter 2 to be string, array given [CORE/cake/libs/model/behaviors/containable.php, line 301]
我试过添加joins
到那里的数组中,但它没有改变任何东西。
这些是我传递给 find 方法的选项。
$options = array(
'contain' => array(
'Answer' => array(
'conditions' => array('Answer.type' => 'answer'),
'joins' => array(
$this->votesJoin()
),
'Comment' => array(
'conditions' => array('Comment.type' => 'comment'),
'joins' => array(
$this->votesJoin()
)
)
),
'Comment' => array(
'conditions' => array('Comment.type' => 'comment'),
'joins' => array(
$this->votesJoin()
)
),
'User',
'Tag' => array()
),
'joins' => array(
$this->votesJoin()
),
'conditions' => array(
'Question.id' => $id
)
);
return $this->find('first', $options);
返回以下votesJoin()
数组。
(
[table] => (SELECT Vote.node_id, SUM(value) as total FROM votes AS `Vote` WHERE 1 = 1 GROUP BY `Vote`.`node_id` )
[alias] => Vote
[conditions] => Vote.node_id = Question.id
)
我正在尝试做的事情:每个用户都可以对一个节点投赞成票/反对票(问题/答案/评论)。通过加入,我试图添加这些选票的总和。 数据库 http://github.com/navale/QA/wiki/img/datamodel.png