我的架构具有以下关系:
User hasMany Transaction belongsTo User
Item hasMany Transaction belongsTo Item
User hasManyAndBelongsTo Item using Transaction as join table
我想退货
属于
. 我可以通过
$this->User->find('all', array( 'conditions' =>
array( 'User.id' => $userId ) ) )
我可以用
$this->Item->find( 'all', array( 'conditions =>
array( 'Item.symbol' => $itemSymbol ) );
但是,如果我尝试在$this->Item->find()、$this->Item->User->find()、$this->User->Item->find()、$this->User->find()或$this->User->Item->find()上使用条件数组('Item.symbol'=>$itemssymbol,'User.id'=>$userId),则会得到错误
SQL Error: 1054: Unknown column 'Item.id' in 'where clause'
或
SQL Error: 1054: Unknown column 'Item.symbol' in 'where clause'
相关信息:
//User.php关联
// a user hasMany transactions
var $hasMany = array('Transaction' =>
array('className' => 'Transaction',
'order' => 'Transaction.created DESC', // order by descending time of transaction
//'limit' => '1', // change this if we need more, for example, if we need a user transaction history
'foreignKey' => 'user_id',
)
);
// a user hasAndBelongsTo items through transactions
var $hasAndBelongsToMany = array('Item' =>
array('className' => 'Item',
'joinTable' => 'transactions',
'foreignKey' => 'user_id',
'associationForeignKey' => 'item_id',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
)
);
//Item.php关联
var $hasMany = array('Transaction' =>
array('className' => 'Transaction',
'order' => 'Transaction.created DESC',
//'limit' => '1', // change this if we need more, for example, if we need a item transaction history
'foreignKey' => 'item_id',
)
);
// a item hasAndBelongsTo users through transactions
var $hasAndBelongsToMany = array('User' =>
array('className' => 'User',
'joinTable' => 'transactions',
'foreignKey' => 'item_id',
'associationForeignKey' => 'user_id',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
)
);
//Transaction.php关联:
var $belongsTo = array('User', 'Item');