0

私のCakephpアプリには2つのモデル定義があります

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);
  }
}

およびCustomerOrder.php

class CustomerOrder extends AppModel {

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

ここで、Customer モデルは、そのコンストラクター引数に基づいて、3 つの mysql テーブルからデータベース テーブル名を動的に取得します。顧客がコンストラクターをオーバーライドしたために 2 番目のモデルを照会すると、バインド モデルで適切なコンストラクターを呼び出すことができないため、mysql エラーが発生します。

これを行うために $belongsTo に追加のパラメーターはありますか? またはどのようにこれを達成することができます。

前もって感謝します。

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 に答える