Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Though Rails 3 AR doesn't give you an or operator you can still achieve the same result without going all the way down to SQL and use Arel directly. By that I mean that you can do it like this:</p> <pre><code>t = Question.arel_table Question.where(t[:user_id].in(self.friends.ids).or(t[:username].in(self.friends.usernames))) </code></pre> <p>Some might say it ain't so pretty, some might say it's pretty simply because it includes no SQL. Anyhow it most certainly could be prettier and there's a gem for it too: MetaWhere</p> <p>For more info see this railscast: <a href="http://railscasts.com/episodes/215-advanced-queries-in-rails-3">http://railscasts.com/episodes/215-advanced-queries-in-rails-3</a> and MetaWhere site: <a href="http://metautonomo.us/projects/metawhere/">http://metautonomo.us/projects/metawhere/</a></p> <p>UPDATE: Later Ryan Bates has made another railscast about metawhere and metasearch: <a href="http://railscasts.com/episodes/251-metawhere-metasearch">http://railscasts.com/episodes/251-metawhere-metasearch</a> Later though Metawhere (and search) have become more or less legacy gems. I.e. they don't even work with Rails 3.1. The author felt they (Metawhere and search) needed drastic rewrite. So much that he actually went for a new gem all together. The successor of Metawhere is Squeel. Read more about the authors announcement here: <a href="http://erniemiller.org/2011/08/31/rails-3-1-and-the-future-of-metawhere-and-metasearch/">http://erniemiller.org/2011/08/31/rails-3-1-and-the-future-of-metawhere-and-metasearch/</a> and check out the project home page: <a href="http://erniemiller.org/projects/squeel/">http://erniemiller.org/projects/squeel/</a> "Metasearch 2.0" is called Ransack and you can read something about it from here: <a href="http://erniemiller.org/2011/04/01/ransack-the-library-formerly-known-as-metasearch-2-0/">http://erniemiller.org/2011/04/01/ransack-the-library-formerly-known-as-metasearch-2-0/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload