2011-11-14 2 views
1
인 이웃 레코드

news, news_n_typesn_types의 세 데이터베이스 테이블이 있습니다.cakephp - 태그 유형이

n_types 테이블은 다양한 유형의 뉴스 태그로 채워집니다.

news_n_types 테이블 맵 n_types ~ news.

뉴스 게시판은 다양한 뉴스 유형에 속할 수 있습니다. 특별한 새로운 유형의 뉴스 게시판의 이웃을 찾으려고합니다.

지금까지 내가 시도한 모든 것을 작동 시키지만 그 유형의 뉴스 게시물뿐만 아니라 모든 뉴스 게시물을 검색합니다.

$this->News->bindModel(array('hasOne' => array('NewsNType'))); 
     $neig = $this->News->find('neighbors', array(
      'fields' => array('News.*') 
     )); 

나는 뉴스 나 SQL 오류받을 유형 필터링 조건을 추가하면

$this->News->bindModel(array('hasOne' => array('NewsNType'))); 
     $neig = $this->News->find('neighbors', array(
      'fields' => array('News.*'), 
      'conditions' => array('NewsNType.n_type_id' => $typeID) 
     )); 

무엇 오전 (SQL 오류 : 'where 절'에서 알 수없는 열 'NewsNType.n_type_id': 1054) 내가 잘못하고있어? 데이터보고 후 요청

업데이트는 이전을 반환하지로도 작동하지 않을 수, 첫 번째 쿼리에서 반환.

응용 프로그램/컨트롤러/news_controller.php 문서에 따르면 (라인 102)

Array 
(
[prev] => 
[next] => Array 
    (
     [News] => Array 
      (
       [id] => 1 
       [title] => TEST 1 
       [date] => 1319935806 
       [body] => TEST 1 
       [excerpt] => TEST 1 
      ) 

     [NType] => Array 
      (
       [0] => Array 
        (
         [id] => 1 
         [label] => Blog 
         [slug] => blog 
         [NewsNType] => Array 
          (
           [id] => 25 
           [news_id] => 1 
           [n_type_id] => 1 
          ) 

        ) 

       [1] => Array 
        (
         [id] => 2 
         [label] => Industry News 
         [slug] => industry_news 
         [NewsNType] => Array 
          (
           [id] => 26 
           [news_id] => 1 
           [n_type_id] => 2 
          ) 

        ) 

      ) 

    ) 

)

+0

첫 번째 쿼리에서 반환 한 데이터의 예를 게시 할 수 있습니까? –

+0

@David Gallagher 나는 더 많은 정보를 추가했습니다 – Paramount

+0

다음으로 ID가 1 일 때 나는 이전에있을 것이라고 기대하지 않습니다. 더 걱정되는 것은 다음에 NewsNType이 없다는 사실입니다. –

답변

1

몇 가지 테스트 후 찾았어요 이 방법으로 find('neighbors')을 사용할 때 다른 테이블의 조건을 사용할 수 없습니다. 가입을해야합니다 :

$joins = array(
    array('table' => 'news_n_types', 
     'alias' => 'NewsNType', 
     'type' => 'LEFT', 
     'conditions' => array(
      'NewsNType.news_id = News.id', 
     ) 
    ) 
); 
$conditions = array('NewsNType.n_type_id' => $typeID); 
$neig = $this->News->find('neighbors', array('field' => 'id', 'value' => 1, 'joins' => $joins, 'conditions' => $conditions)); 
0

[find('neighbors')] does not honor a model’s default recursive var. The recursive setting must be passed in the parameters on each call.

사용해보십시오 :

$neig = $this->News->find('neighbors', array(
     'fields' => array('News.*'), 
     'conditions' => array('NewsNType.n_type_id' => $typeID), 
     'recursive' => 1 
    )); 
+0

재귀 적으로 1로 설정 한 후 결과로 첫 번째 게시물을 업데이트했습니다. – Paramount