Ruby on Rails Wednesday, August 31, 2011

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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8LKcfxmrF3gJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment