0

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 #                    ascend_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?

rid
  • 61,078
  • 31
  • 152
  • 193
Satchel
  • 16,414
  • 23
  • 106
  • 192

1 Answers1

0

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)
Ernie
  • 896
  • 5
  • 7
  • yes, I think this is the right thing, but for some reason it isn't coming out right, but let me play with it a little more, maybe I am doing something wrong...I think I was using plural joins(:contacts)...it's just singular, huh? – Satchel Jun 15 '11 at 22:11