I know this was discussed a while back, but I couldn't find the thread. Issue is that has_one associations don't cache nils, whereas has_many do cache the empty array.

Causes a big performance issue when you do things like:

  class People < ActiveRecord::Base
    has_one :thing
  end

  Person.find(:all, :include => :thing).each do |p|
    ...do something here with p.thing...
  end

This results in lots of unnecessary and unexpected queries for all those people that don't have things.

So...is this intentional? Would core be open to a patch that allowed AR to differentiate between "nil -- this association needs to be loaded" and "nil -- the target is actually nil"?
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to