Created
March 13, 2011 19:31
-
-
Save ernie/868353 to your computer and use it in GitHub Desktop.
Sample queries with MW 2.0
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
Article.joins{person.comments}.where{person.comments.body =~ '%hello%'}.to_sql | |
# => "SELECT \"articles\".* FROM \"articles\" INNER JOIN \"people\" ON \"people\".\"id\" = \"articles\".\"person_id\" INNER JOIN \"comments\" ON \"comments\".\"person_id\" = \"people\".\"id\" WHERE \"comments\".\"body\" LIKE '%hello%'" | |
Person.where{(id + 1) == 2}.first | |
# => #<Person id: 1, parent_id: nil, name: "Aric Smith", salary: 31000> | |
Person.where{(salary - 40000) < 0}.to_sql | |
# => "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"salary\" - 40000 < 0" | |
p = Person.select{[id, name, salary, (salary + 1000).as('salary_after_increase')]}.first | |
# => #<Person id: 1, name: "Aric Smith", salary: 31000> | |
p.salary_after_increase # => 32000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment