exists?
AR::Base.exists? used to basically say !find(:first, :conditions =>)...
It now (effectively) says !find(:first, :select => 'id', :conditions
=> )
I imagine this is to save on instantiating a large object with many
columns just to throw it away. This is all good and well, but has
broken some things for us: on some models we have after_find callbacks
that rely on the presence of attributes. In our particular cases we
just moved to setting up those things lazily, you could also check
that the attributes are actually here. However morally I wouldn't
expect exists? to instantiate anything at all, which would make the
problem go away (and in a sense take the above change a little further).
Rewriting exists? as
def exists?(id_or_conditions)
sql = construct_finder_sql(:first, :select =>
"#{quoted_table_name}.#{primary_key}", :conditions =>
expand_id_conditions(id_or_conditions) :limit =>1)
connection.select_all(sanitize_sql(sql)).size > 0
end
does this, but it's rather more verbose, so I'm not sure it's actually
worth it.
Thoughts?
Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---