2011-08-24 2 views
0

나는 hasAndBelongsToMany 조건을 변경하여 블로그 항목을 선택합니다. cakephp 1.3에서는 더 이상 작동하지 않습니다. 이상한 문제가 1.2에서 제대로 작동했기 때문에 모델에서 정적 ID가있는 조건을 넣어 시험하여 (Tag.name => 'libros')을 확인합니다. hasAndBelongsToMany 조건은 통과합니다. 결과를 가져 오게. 컨트롤러hasAndBelongsToMany 모델의 조건을 변경하여 문제가 발생했습니다.

$this->Blog->bindModel(array(
        'hasAndBelongsToMany' => array(
         'Tag' => array('conditions'=>array('Tag.name'=>'libros')) 
      ))); 
      $this->Blog->find('all'); 

에서

var $hasAndBelongsToMany = array('Tag' => 
         array('className' => 'Tag', 
          'joinTable' => 'blogs_tags', 
          'foreignKey' => 'blog_id', 
          'associationForeignKey'=> 'tag_id', 
          'conditions' => '', 
          'order'  => '', 
          'limit'  => '', 
          'unique'  => true, 
          'finderSql' => '', 
          'deleteQuery'=> '' 
         ) 

이제 더 이상 MySQL의 오류를 해달라고,하지만 난 다른 사람의 결과와 다른 기록을 가지고있다. 기묘한.

답변

0

당신이 올바른 데이터베이스 구조가있는 경우,이

$this->Blog->bindModel(array(
         'hasOne' => array(
           'BlogsTag', 
           'FilterTag' => array(
            'className' => 'Tag', 
            'foreignKey' => false, 
            'conditions' => array('FilterTag.id = BlogsTag.tag_id') 
       )))); 
      $data = $this->Blog->find('all', array(
         'fields' => array('Blog.*'), 
         'conditions'=>array('FilterTag.name'=>'libros') 
      )); 

당신이에 대한 자세한 내용이 읽을 수 = 사용해야합니다 http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM

+0

그래 작동을! 나는 당신에게 많이 감사하고 싶다, 이것은 매우 유용하다! – user784083

관련 문제