我最近使用https://github.com/dereuromark/upgrade 将我的 1.3-app 升级到 2.4
但是现在$this->Model->find() 的某些用法不起作用。尤其是与关联模型/表的连接。
导致“where 子句中的未知列 'Bill.customer_id'”。
我的设置:
表格和关联: http: //i.stack.imgur.com/bjOIz.png (图片)
型号:
App::uses('AppModel', 'Model');
class Customer extends AppModel {
public $actsAs = array('Logable', 'Containable');
public $hasMany = array(
'Bill' => array(
'className' => 'Bill',
'foreignKey' => 'customer_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)...
-----------------------------------------------------------------
App::uses('AppModel', 'Model');
class Bill extends AppModel {
public $actsAs = array('Containable', 'Logable', 'Lockable');
public $belongsTo = array(
'Customer' => array(
'className' => 'Customer',
'foreignKey' => 'customer_id',
'conditions' => '',
'fields' => '',
'order' => ''
)...
public $hasAndBelongsToMany = array(
'Stage' => array(
'className' => 'Stage',
'joinTable' => 'bills_stages',
'foreignKey' => 'bill_id',
'associationForeignKey' => 'stage_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)...
--------------------------------------------------------------
App::uses('AppModel', 'Model');
class BillsStage extends AppModel {
public $actsAs = array('Containable', 'Logable', 'Lockable');
public $belongsTo = array(
'Bill' => array(
'className' => 'Bill',
'foreignKey' => 'bill_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Stage' => array(
'className' => 'Stage',
'foreignKey' => 'stage_id',
'conditions' => '',
'fields' => '',
'order' => ''
)...
--------------------------------------------------------
App::uses('AppModel', 'Model');
class Stage extends AppModel {
public $displayField = 'name';
public $actsAs = array('Tree', 'Containable', 'Logable');
public $hasMany = array(
'Bill' => array(
'className' => 'Bill',
'foreignKey' => 'stage_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)...
public $hasAndBelongsToMany = array(
'Bill' => array(
'className' => 'Bill',
'joinTable' => 'bills_stages',
'foreignKey' => 'stage_id',
'associationForeignKey' => 'bill_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)...
在 1.3 中,连接正在工作。在 2.4 中只有一维的 sql 查询。
任何想法?
--编辑--
$billsStages = $this->Customer->Bill->BillsStage->find('all', array(
'conditions' => array(
'Bill.customer_id' => $this->Customer->id,
'Stage.id' => array_keys($vk_stages)
),
'order' => 'BillsStage.created DESC'
));