我正在使用 cakephp,我希望在我的 userController.php 中从另一个表(ingredient_aliases)中检索数据。这是componentAlias的模型
class IngredientAlias extends AppModel {
public $name = 'IngredientAlias';
public $useTable = 'ingredient_aliases';
public $belongsTo = array(
'Ingredient' => array(
'className' => 'Ingredient',
'foreignKey' => 'ingredient_id'
)
);
...
我想从我的 userController.php 中检索表成分别名(最后 10 个创建)中的数据
我尝试过这种模式:
$this->loadModel('IngredientAlias', 2);
$ingg = $this->IngredientAlias->read();
$options['joins'] = array(
array('table' => 'ingredient_aliases',
'alias' => 'ing',
'type' => 'LEFT',
'foreignKey' => 'ing.user_id',
'order' => 'ing.created DESC',
'limit' => 3,
'conditions' => array(
'ing.user_id = User.id'
)
)
);
$options['conditions'] = array( );
$this->set('ingredient',$this->IngredientAlias->find('all', $options));
但这给了我这个错误:错误:SQLSTATE [42S22]:找不到列:1054 Unknown column 'User.id' in 'on clause'
有人能帮我吗?谢谢