Prev | Current Page 407 | Next

Brad Ediger

"Advanced Rails"

select{|u| u.salary > 50_000}.sort_by{|u| u.name}.to_sql
=> "SELECT * FROM users WHERE users.`salary` > 50000 ORDER BY users.name"
>> User.select{|u| u.salary > 50_000}.sort_by{|u| u.name}.to_hash
=> {:order=>"users.name", :conditions=>"users.`salary` > 50000"}
There are many more features, including some syntactic sugar on the standard Ruby
Enumerable methods:
>> User.any?{|u| u.salary > 50_000}
# SELECT count(*) AS count_all FROM users WHERE (users.`salary` > 50000)
=> true
>> User.all?{|u| u.salary < 500_000}
# SELECT count(*) AS count_all FROM users
# SELECT count(*) AS count_all FROM users WHERE (users.`salary` < 500000)
=> true
Consult the Ambition blog post for an overview of all the useful methods and syntax
provided. Ambition is still under heavy development and is certainly subject to
change. At this time, the best source of documentation is the README (available
from the Git repository at git://errtheblog.com/git/ambition), as well as the source
itself.
Og
Og (short for ObjectGraph) is yet another object-relational mapping library for
Ruby. It is part of the Nitro project, which is a web framework similar to Rails. Like
Rails, Nitro is composed of layered components. However, these components take a
different approach to solve the same problems as Rails, and so it is much harder to
use Og with Rails than with Nitro. In particular, the Rails Dependencies system
causes many problems with file loading.


Pages:
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419