Created
May 15, 2012 21:07
-
-
Save amiel/2705150 to your computer and use it in GitHub Desktop.
Which is better?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Collection.arel_table | |
where(t[:public].eq(true).or(t[:user_id].eq(user.id))) | |
# or | |
where('public = ? OR user_id = ?', true, user.id) |
Not an issue in the simple case, but I believe that the second form will follow/respect/use aliasing of the table (as AR does sometimes with associations).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@intjonathan thanks, that's a good point; building arbitrarily complex queries is pretty hairy with that second form unless it's just
AND
Can you give an example of nice use of arel?