Hello,
An issue with a Rails named scope has been stumping me for quite
sometime, and I’m hoping someone can point out the flaw. I have a model,
Machine, with the following named scope:
named_scope :needs_updates, lambda {
{ :select => self.column_names.collect{|c|
%Q/“machines”."#{c}"/}.join(’,’),
:group => self.column_names.collect{|c|
%Q/“machines”."#{c}"/}.join(’,’),
:joins => ‘LEFT JOIN “machine_updates” ON
“machine_updates”.“machine_id” = “machines”.“id”’,
:having => [’“machines”.“manual_updates” = ? AND
“machines”.“in_use” = ? AND (MAX(“machine_updates”.“date”) IS NULL OR
MAX(“machine_updates”.“date”) < ?)’,
true, true, UPDATE_THRESHOLD.days.ago]
}
}
The named scope works fine in development mode, and with my current
dataset returns two models as expected. In production mode, however, it
returns two models, but they are uninitialized; that is, actual objects
are returned, but all the fields (including id) are nil. When inspecting
the return value of the named scope in the console, the following is
returned:
[#, #]
(That is, objects with no values.)
The production and development databases are essentially the same—both
are using SQLite for DB storage. I’m using Rails 2.3.5 with no plugins.
Any idea what’s wrong?
Michael D.
[email protected]