Why does this Rails named scope return empty (uninitialized?) objects?
Posted
by mipadi
on Stack Overflow
See other posts from Stack Overflow
or by mipadi
Published on 2010-04-02T18:57:45Z
Indexed on
2010/04/02
19:03 UTC
Read the original article
Hit count: 290
In a Rails app, I have a model, Machine
, that contains the following named scope:
named_scope :needs_updates, lambda {
{ :select => self.column_names.collect{|c| "\"machines\".\"#{c}\""}.join(','),
:group => self.column_names.collect{|c| "\"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]
}
}
This named scope works fine in development mode. In production mode, however, it returns the 2 models as expected, but the models are empty or uninitialized; that is, actual objects are returned (not nil
), but all the fields are nil
. For example, when inspecting the return value of the named scope in the console, the following is returned:
[#<Machine >, #<Machine >]
But, as you can see, all the fields of the objects returned are set to nil
.
The production and development environments are essentially the same. Both are using a SQLite database.
Any ideas what's going wrong?
© Stack Overflow or respective owner