Quick ORM question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Quick ORM question

Zack Chandler
Quick question on this query:

@item.entries = Entry.find_recent(@td.id, 10) || []

My development log file shows that rails makes 2 calls to database!  Is
rails ORM not smart enough to know to not load the lvalue of assignment thus
causing another expensive db call?  Below are the stubbed models and a log
snip.

class Entry < ActiveRecord::Base
  belongs_to :tracking_definition  
  def self.find_recent(td_id, limit=10)
    find(:all, :conditions => ["tracking_definition_id = ?", td_id], :limit
=> limit)
  end
end

class Item < ActiveRecord::Base
  has_many :entries
end

------------------- log snip from this one line
---------------------------------------------------
  Item Load (0.000000)   SELECT * FROM items WHERE
(item_id = 1) LIMIT 10
  Entry Load (0.000000)   SELECT * FROM items WHERE
(entries.item_id = 1) 

_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails