0

find('list') メソッドを使用しようとしていますが、成功しません。

支払いの種類をリストしようとすると、データベースの1つのテーブルだけが正しく表示され、別のテーブルは正しいSQLを実行していますが、nullが返されます(SQLが行を取得しても)。

Tpagamento の 1 つのフィールドを読み取ろうとすると動作します Tpagamento の displayField を 'id' に変更すると動作しますが、クエリには ID しか表示されません。

シナリオは次のとおりです。

(Parcelamento と Tpagamento には同じデータベース フィールドがあります)

表示方法:

public function view($id = null) {

    $this->Ordemservico->id = $id;
    if (!$this->Ordemservico->exists()) {
        $this->Session->setFlash('This Order does not exist..','flash_error');
        $this->redirect(array('action' => 'index'));
    }

            //Listing all orders // THIS IS WORKING
    $os = $this->Ordemservico->read(null, $id);
    $this->set('os',$os);

    //Listing the types of paying //THIS  IS WORKING
    $this->loadModel('Parcelamento');
    $parcelamentos = $this->Parcelamento->find('list');
    $this->set('parcelamentos',$parcelamentos);


    $this->loadModel('Tpagamento'); // THIS IS NOT WORKING
    $tpagamento = $this->Tpagamento->find('list');
    $this->set('tpagamento ',$tpagamento );

            //Read a specific type of paying, WORK!
    $this->loadModel('Tpagamento'); // THIS IS WORKING
    $tpagamentos = $this->Tpagamento->read(null,'5');
    $this->set('tpagamentos',$tpagamentos);

}

OrdemServico モデル:

class Ordemservico extends AppModel {

    public $displayField = 'cliente_id';

    public $belongsTo = array(      
        'Tpagamento' => array(
            'className' => 'Tpagamento',
            'foreignKey' => 'tpagamento_id',
        ),
        'Parcelamento' => array(
            'className' => 'Parcelamento',
            'foreignKey' => 'parcelamento_id',
        ),
    );

}

モデル:

class Tpagamento extends AppModel {

    public $useTable = 'tpagamentos';

    public $displayField = 'nome';

    public $hasMany = array(
        'Ordemservico' => array(
            'className' => 'Ordemservico',
            'foreignKey' => 'tpagamento_id',
        ),

    );



}

パーセラメント モデル:

class Parcelamento extends AppModel {

    public $displayField = 'nome';

    public $hasMany = array(
        'Ordemservico' => array(
            'className' => 'Ordemservico',
            'foreignKey' => 'parcelamento_id',
        ),

    );



}

生成された SQL ダンプ:

4   SELECT `Parcelamento`.`id`, `Parcelamento`.`nome` FROM `tereza`.`parcelamentos` AS `Parcelamento` WHERE 1 = 1       5   5   0

5   SELECT `Tpagamento`.`id`, `Tpagamento`.`nome` FROM `tereza`.`tpagamentos` AS `Tpagamento` WHERE 1 = 1       4   4   0

6   SELECT `Tpagamento`.`id`, `Tpagamento`.`nome`, `Tpagamento`.`created`, `Tpagamento`.`modified` FROM `tereza`.`tpagamentos` AS `Tpagamento` WHERE `Tpagamento`.`id` = 5 LIMIT 1      1   1   0
4

2 に答える 2