Forum: Ruby on Rails Quick ORM question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Zack C. (Guest)
on 2005-12-16 08:36
(Received via mailing list)
Quick question on this query:

@item.entries = Entry.find_recent(, 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
causing another expensive db call?  Below are the stubbed models and a

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)

class Item < ActiveRecord::Base
  has_many :entries

------------------- 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) 
This topic is locked and can not be replied to.