내 프로젝트에서 메시지 검색을위한 작업을하고 있는데, 두 가지 모델이 있습니다 : Msgcontent와 Msgblock.Relationship은 Msgblock hasMany Msgcontent입니다. 내가하고 싶은 것은 ?cakephp에 hasMany 관계에 대한 조건을 찾았습니다.
if($keyword)
{
$conditions['and'] = array(
'Msgcontent.content LIKE'=>'%'.$keyword.'%',
'Msgcontent.content <>'=>''
);
$results = $this->Msgblock->Msgcontent->find('all',array('group'=>array('Msgblock.chatsessionid'),'conditions'=>$conditions));
}
그것은이 좋은 work.Is 더 나은 솔루션을 감사하지 보인다 다음과 같이 몇 가지 검색 keyword.My 코드 Msgcontent를 포함 Msgblock 기록합니다. ,
$ids = $this->Msgblock->Msgcontent->find('all', array(
'fields' => array('Msgcontent.msgblock_id'),
'recursive' => -1,
'conditions' => ...
));
$this->Msgblock->find('all', array(
'conditions' => array('Msgblock.id' => Set::extract('/Msgcontent/msgblock_id', $ids))
));
나는 이렇게 해냈고 Unknown column 'Msgcontent.content'in 'where clause'와 같은 오류를 일으킬 것이다. – Young
@SpawnCxy 내 나쁜, 다른 방법은 (belongsTo) 작동합니다. – deceze
@SpawnCxy 답변이 업데이트되었습니다. – deceze