I have 4 tables:
- content
- relation
- subject
- group
content:
id(int)
title(varchar)
text(text)
subject:
id(int)
title(varchar)
prent_id(int)
group:
id(int)
title(varchar)
relation:
id(int)
content_id(int)
group_id(int)
subject_id(int)
relation to content is many to many.
group to content is many to many.
subject to content is many to many.
Content may belong to several subjects or several groups.
I want to execute a query somewhat like this:
select * from relation where group_id = 1,3 and subject_id = 1,4,6,7
You can use
findAllByAttributes:That will give you something like (actual query may contain alias):
However if you want :
where group_id IN (1,3) OR subject_id IN (1,4,6,7)(i.e OR instead of AND) then you will have to useCDbCriteria:You could also use
addInCondition:Remember to bind parameters incase you are taking input from user, though. Something like this: