More Related Content Similar to ActiveRecord Query Interface Similar to ActiveRecord Query Interface (20) ActiveRecord Query Interface14. „...integrate Arel into the existing
implementation of ActiveRecord...“
http://socghop.appspot.com/gsoc/student_project/show/google/gsoc2009/rails/t124025364581
15. „Arel is a Relational Algebra for
Ruby“
http://github.com/rails/arel
22. Example (deprecated)
● Owner.find(:first)
● Owner.find(:first, :conditions =>
{:name => 'test'})
But that is OK:
● Owner.find(1)
● Owner.find(1,2)
24. Example (deprecated)
● named_scope :red, :conditions =>
{ :colour => 'red' }
● default_scope :order => 'last_name'
28. Example (New API)
● where
● having
● select
● group
● order
● limit
● offset
● joins
● includes
● lock
● readonly
● from
31. Example
● Rails 2
● Owner.find(:first, :conditions =>
{:name => 'test'})
● Rails 3
● Owner.where(:name => 'test')
● with DB-Query
– Owner.where(:name => 'test').each{ |o|
puts o.name }
33. Example
● Rails 2
● Owner.find(:first, :conditions =>
{:name => 'test'})
● Rails 3
● Owner.where(:name => 'test').first
35. Example
● Rails 3
@books = Book.order(params[:order))
@published_books = @books.where(:published =>
true)
@unpublished_books = @books.where(:published =>
false)
36. Example
● Rails 2
● Book.find(:all, :conditions => ["price
<= ?", 10], :include => :authors)
● Rails 3
● Book.where("price
<= ?",10).includes(:authors)
38. Example
● Rails 2
● named_scope :red, :conditions => {
:colour => 'red' }
● Rails 3.0
● scope :red, :conditions => { :colour
=> 'red' }
● Rails 3.2
● scope :red, where(:colour => 'red')
39. Sources
● m.onkey.org/2010/1/22/active-record-query-
interface
● magicscalingsprinkles.wordpress.com/2010/01/
28/why-i-wrote-arel/
● edgeapi.rubyonrails.org/
● slideshare.net/GreggPollack/rails-3-beautiful-
code-3219240
● flickr.com/photos/fofurasfelinas/2502823019/siz
es/o/
40. Sources
● flickr.com/photos/timcaynes/148110505/
● flickr.com/photos/gurana/3831997459/sizes/m/