CakePHP 1.3 - Unknown column in where clause

前端 未结 5 846
情话喂你
情话喂你 2021-01-18 02:02

I\'m working on an already existing cakephp 1.3 project and I needed to add a new table to the database. I have this in my controller:

    $conditions = arra         


        
5条回答
  •  独厮守ぢ
    2021-01-18 02:30

    In your model add containable behavior

    class Email extends AppModel {
        var $name = 'Email';
    
        var $actsAs = array('Containable');
    
        var $belongsTo = array
        (
            'Person' => array
            (
                'className' => 'Person',
                'foreignKey' => 'person_id'
            ),
            'ShootingPlacement' => array
            (
                'className' => 'ShootingPlacement',
                'foreignKey' => 'shooting_placement_id'
            )
        );
    }
    

    Just write the below code in your controller.

    $this->ShootingPlacement->recursive = 2;
    $this->ShootingPlacement->contain = array(
        'Shooting',
        'Person' => array(
            'Email'
        )
    );
    $conditions = array(
      'ShootingPlacement.person_id' => $id,
      'Email.shooting_placement_id' => 'ShootingPlacement.id'
    );
    $shootingPlacements = $this->ShootingPlacement->find('all', compact('conditions'));
    

    Hope this helps you.

提交回复
热议问题