When I was using searchlogic, I couuld use the following:
27 # @todos = Todo.contact_user_id_is(current_user).
28 # contact_campaign_id_is(@campaign).
29 # current_date_lte(Date.today).
30 # done_date_null.
31 # ascend_by_contact_id.
32 # asce开发者_如何学JAVAnd_by_current_date
For example, it would allow me to search for the campaign belong to a contact that belonged to the Todo record.
This is what I've tried (not sure how to do the sorting:
22 @todos = Todo.joins(:contacts).where(:user_id.eq => current_user,
23 :contacts => { :campaign_id.eq => @campaign.id},
24 :current_date.lteq => Date.today,
25 :done_date.not_eq => nil)
How do I do something like that with metawhere?
If Todo belongs_to or has_one contact, which I'm assuming is the case based on the Searchlogic query above, you would want to do something like (untested):
@todos = Todo.joins(:contact).
where(
:contact => {
:user_id => current_user.id,
:campaign_id => @campaign.id
},
:current_date.lteq => Date.today,
:done_date.not_eq => nil
).
order(:contact_id, :current_date)
精彩评论