它在控制器中工作:
$topic_word = ClassRegistry::init('TopicsTopicWord');
$result = $topic_word->find('all', [
'contain' => ['TopicWord'],
'conditions' => [
'TopicsTopicWord.topic_id' => '1777125',
'TopicWord.status >=' => 1,
]
]);
var_dump($result); die();
但是当我从命令行调用它时,同样的代码给了我这个错误:
cake feed make
“where子句”中的“TopicWord.status”
class TopicsTopicWord extends AppModel
{
public $recursive = -1;
public $actsAs = ['Containable'];
public $belongsTo = ['TopicWord'];
...
}
class TopicWord extends AppModel
{
public $recursive = -1;
...
Cake版本:2.2.1
PHP版本:5.4.23
+++更新+++
感谢@ndm的评论,我检查了日志文件,控制器中的工作sql确实包含:
LEFT JOIN
`db`.`topic_words` AS `TopicWord` ON
(`TopicsTopicWord`.`topic_word_id` = `TopicWord`.`id`)
但是其他的没有左连接。。。sql部分:
SELECT
TopicsTopicWord.id, TopicsTopicWord.topic_id, TopicsTopicWord.topic_word_id
FROM
db.topics_topic_words AS TopicsTopicWord
WHERE
TopicsTopicWord.topic_id = 1777125 AND TopicWord.status >= 1
非常感谢@ndm。没错,它确实返回“AppModel”:
$topic_word = ClassRegistry::init('TopicsTopicWord');
var_dump(get_class($topic_word)); die();
...
/Users/xxx/mdpr-vagrant/projects/xxx/app/Lib/FeedFormatter/LineFormatter.php:151:
string(8) "AppModel"
控制器中的相同代码返回:
.../app/Controller/TopicsController.php:711:string 'TopicsTopicWord' (length=15)
https://github.com/cakephp/cakephp/issues/9133