0

I have two Model definition in my Cakephp app

Customer.php

class Customer extends AppModel {

    var $name = 'Customer';
    public function Customer($tableId){
    //.. code to assign a table name based on $tableId
    return parent::__construct("id", $this->useTable);
  }
}

and CustomerOrder.php

class CustomerOrder extends AppModel {

    var $name = 'CustomerOrder';
    var $belongsTo = array('Customer ' => array(
            'className' => 'Customer',
            'foreignKey' => 'customer_id'
        ));
}

Here Customer model would get its database tablename dynamically out of three mysql tables based from that constructor argument. When i query second model because Customer has overridden constructor i get mysql error because it cannot invoke right constructor in bind model.

is there additional parameter in $belongsTo to do this? or how can achieve this.

thanks in advance.

4

1 回答 1

0

我认为您正在以另一种语言方式构建课程。在 php 中,构造函数就像

class Customer extends AppModel {
    var $name = 'Customer';  //note: this line is really not necessary

    public function __construct($id = false, $table = null, $ds = null) {
        //.. code to assign a table name based on $tableId
        return parent::__construct("id", $this->useTable, $ds);
    }
}

如果您进行该更改,是否仍然会给您该错误?

(顺便说一句,$ds是 DataSource 连接名称,您可以查看代码以获取更多信息)。

于 2013-06-07T13:58:50.890 回答