2012-01-16 2 views
0

내 쿼리가 나에게 library_id 만 반환합니다. 내 견해에 제목을 표시해야합니다. 어떻게 보여줄 제목을 얻을 수 있습니까? 여기 여기 내 도서관 모델 여기더 많은 필드를 가져 오는 방법

class Library extends AppModel { 

    //The Associations below have been created with all possible keys, those that are not needed can be removed 

/** 
* hasMany associations 
* 
* @var array 
*/ 
    public $hasMany = array(
     'Share' => array(
      'className' => 'Share', 
      'foreignKey' => 'library_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => 'Title', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ), 
     'Work' => array(
      'className' => 'Work', 
      'foreignKey' => 'library_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ) 
    ); 

} 

컨트롤러 내 추가 방법입니다 내 주 모델

public $belongsTo = array(
     'Person' => array(
      'className' => 'Person', 
      'foreignKey' => 'person_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ), 
     'Library' => array(
      'className' => 'Library', 
      'foreignKey' => 'library_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 

입니다

public function add() { 
     if ($this->request->is('post')) { 
      $this->Share->create(); 
      if ($this->Share->save($this->request->data)) { 
       $this->Session->setFlash(__('The share has been saved')); 
       $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The share could not be saved. Please, try again.')); 
      } 
     } 
     $people = $this->Share->Person->find('list'); 
     $libraries = $this->Share->Library->find('list'); 
     $this->set(compact('people', 'libraries')); 
    } 

그리고 여기 내이다

<div class="shares form"> 
<?php echo $this->Form->create('Share');?> 
    <fieldset> 
     <legend><?php echo __('Add Share'); ?></legend> 
    <?php 
     echo $this->Form->input('person_id'); 
    echo $this->Form->input('library_id'); 
     echo $this->Form->input('share'); 

    ?> 
    </fieldset> 
<?php echo $this->Form->end(__('Submit'));?> 
</div> 

답변

0

위의 질문에 신경 쓰지 마십시오.

$ libraries-> share-> library-> find ('list', array ('fields'=> 'Library.Title')));

LibrariesController에서

감사

관련 문제