$tagged = Os :: model()-> withTags("windows, windows7, windowsXp")-> find();
나는 다음과 같은 창의 태그 된 기록, Windows7의, 지금 WindowsXP를 검색 할 수 있습니다.기본 조건 연산자를 Taggable 확장에서 OR에서 AND로 변경할 수 있습니까?
기본적으로 태그는 AND 조건의 조건을 생성합니다. 태그에 OR 연산자를 사용하고 싶습니다. 레코드에 windows가 포함되어있는 경우 windows7은 검색되지만 windowsXp는 검색되지 않습니다.
나는 확장 폴더에 오는 ETaggableBehavior.php에 getFindByTagsCriteria()를 편집하여, 해결 방법을 찾기 위해 관리했습니다.
/**
* Get criteria to limit query by tags.
* @access private
* @param array $tags
* @return CDbCriteria
*/
protected function getFindByTagsCriteria($tags) {
$criteria = new CDbCriteria();
$pk = $this->getOwner()->tableSchema->primaryKey;
if(!empty($tags)){
$conn = $this->getConnection();
$criteria->select = 't.*';
if(count($tags) >0){
$criteria -> join .= "
JOIN {$this->getTagBindingTableName()} bt
ON t.{$pk} = bt.{$this->getModelTableFkName()}
JOIN {$this->tagTable} tag0
ON tag0.{$this->tagTablePk} = bt.{$this->tagBindingTableTagId} AND (";
for($i = 0, $count = count($tags); $i < $count; $i++){
$tag = $conn->quoteValue($tags[$i]);
$criteria->join .= " tag0.`{$this->tagTableName}` = $tag OR";
}
$criteria -> join = rtrim($criteria -> join, "OR");
$criteria -> join .= ")";
}
}
if($this->getScopeCriteria()){
$criteria->mergeWith($this->getScopeCriteria());
}
return $criteria;
}
정말 플러그인 자체를 수정하지 않고도 다른 방법으로 감사하겠습니다.
내 질문이 업데이트되었습니다. 당신의 대답과 비슷한 방식으로 나는 플러그인의 메인 파일을 수정했다. 문제는 어떤 부작용이 생길지 전혀 모른다는 것입니다. JOIN에서 쿼리를 만들고 WHERE (조건 OR AND 조건)를 통해 태그를 검색하지 않습니다. https://github.com/yiiext/taggable-behavior/blob/master/ETaggableBehavior.php#를 확인하십시오. L499 –
511 줄의 join 문 끝에서'$ tag- $ tag.name {$ this-> tagTableName}'= $ tag'을 제거하고 자신의 ' 조건 '문을'AND '대신'OR '로? 그래도 그걸 좀 더 고칠 필요가 있을까요? – Stu