arel

6 views
Skip to first unread message

Игнат Воробьёв

unread,
Aug 31, 2011, 6:01:33 AM8/31/11
to Ruby on Rails: Talk
I don`t want to use 'find_by_sql', but currently it is the only way
to get ordered relation for pagination. It would be good to use 'last'
and 'first' methods.

I have modelname.where(...).union(modelname.where(...))
how i can get something like
modelname.where(...).union(modelname.where(...)).order('something')?

Tim Shaffer

unread,
Aug 31, 2011, 8:56:57 AM8/31/11
to rubyonra...@googlegroups.com
So essentially you're trying to do something like this?

  modelname.where(:name => "foo").union(modelname.where(:name => "bar"))

Since it's the same model, I don't think there's a reason to use a union in this case. Isn't this really just an OR operator?

  select * from modelname where name = "foo" or name = "bar"

Couldn't you just use the or operator like so?

  modelname.where("name = ? or name = ?", "foo", "bar").order("something")

Granted, your WHERE clause is probably more complex than that, but the principle should be the same.
Reply all
Reply to author
Forward
0 new messages