我正在开发Cake
PHP 1.2应用程序.我有一个模型“用户”通过连接表定义了与其他表的几个HABTM关系.
原文链接:https://www.f2er.com/php/135149.html我现在的任务是根据存储在其中一个HABTM表中的数据查找用户信息.不幸的是,当查询执行时,我的条件被拒绝,并显示有关丢失表的错误.在检查时,似乎CakePHP不包括select语句中的任何HABTM表.
我的用户HABTM关系如下:
var $hasAndBelongsToMany = array( 'Course' => array( 'className' => 'Course','joinTable' => 'course_members','foreignKey' => 'user_id','associationForeignKey' => 'course_id','conditions' => '','order' => '','limit' => '','uniq' => false,'finderQuery' => '','deleteQuery' => '','insertQuery' => '' ),'School' => array( 'className' => 'School','joinTable' => 'school_members','associationForeignKey' => 'school_id','Team' => array( 'className' => 'Team','joinTable' => 'team_members','associationForeignKey' => 'team_id','insertQuery' => '' ) );
错误是:
sql Error: 1054: Unknown column
‘School.name’ in ‘where clause’
最后,它正在尝试执行的查询
SELECT `User`.`id`,`User`.`username`,`User`.`password`,`User`.`firstName`,`User`.`lastName`,`User`.`email `,`User`.`phone`,`User`.`streetAddress`,`User`.`city`,`User`.`province`,`User`.`country`,`User `.`postal`,`User`.`userlevel`,`User`.`modified`,`User`.`created`,`User`.`deleted`,`User`.`deleted_date ` FROM `users` AS `User` WHERE `User`.`id` = 6 AND `School`.`name` LIKE '%Test%' LIMIT 1