Как получить всю связанную информацию в таблицах отношений? - PullRequest
0 голосов
/ 25 февраля 2012

У меня есть несколько связанных таблиц, и в основном это Модель:

<?php
App::uses('AppModel', 'Model');
class Information extends AppModel {
public $useTable = 'informations';
public $displayField = 'name';
public $validate = array(
    'name' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'The field name can not be empty',
        ),
    ),
    'lastname' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'The field lastname can not be empty',
        ),
    ),
    'email' => array(
        'email' => array(
            'rule' => array('email'),
            'message' => 'The email address is not correct',
        ),
    ),
);

public $belongsTo = array(
    'Country' => array(
        'className' => 'Country',
        'foreignKey' => 'countries_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);

public $hasMany = array(
        'Education' => array(
                'className' => 'Education',
                'foreignKey' => 'informations_id',
                'dependent' => true
        ),
        'Experience' => array(
                'className' => 'Experience',
                'foreignKey' => 'informations_id',
                'dependent' => true
        ),
        'Attachment' => array(
                'className' => 'Attachment',
                'foreignKey' => 'informations_id',
                'dependent' => true
        )
);

}

Мне нужно получить все данные, связанные с идентификатором, но когда я пытаюсь получить данные, используя этот код:

  public function view($id = null) {
    $this->Information->id = $id;
    if (!$this->Information->exists()) {
        throw new NotFoundException(__('Invalid information'));
    }
    $this->set('information', $this->Information->read(null, $id));
}

Информация из таблиц Образование, Опыт и Приложение не показана, только эта информация получена:

Array
(
   [id] => 9
   [name] => Reynier
   [lastname] => Perez Mira
   [email] => reynierpm@gmail.com
   [mobile_phone] => 04241805609
   [home_phone] => 02735555899
   [address] => asdas
   [picture] => skills.png
   [other_information] => asdasdasd
   [recruitment_status] => Call for Interview
   [countries_id] => 9
)

Почему? Я что-то пропустил?

1 Ответ

1 голос
/ 25 февраля 2012

Обновите вашу функцию, чтобы установить рекурсивную информацию:

public function view($id = null) {
    $this->Information->id = $id;
    if (!$this->Information->exists()) {
        throw new NotFoundException(__('Invalid information'));
    }
    $this->Information->recursive = 1;
    $this->set('information', $this->Information->read(null, $id));
}

Затем убедитесь, что все ваши отношения в вашей информационной модели настроены так, чтобы указывать на другие модели, которые вы хотите включить.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...