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: [#<Machine >, #<Machine >] (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 Dippery mdippery-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 15, 6:46 pm, Michael Dippery <mdipp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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: > > [#<Machine >, #<Machine >] > > (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?Have you tried running the sql this generates by hand and seeing if the result set looks normal ? Fred> > ---- > Michael Dippery > mdipp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Have you tried running the sql this generates by hand and seeing if > the result set looks normal ?Yep. Running the SQL generated by Rails (via script/dbconsole) returns the expected result set. ---- Michael Dippery mdippery-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.