I''m trying to use the :group option in an ActiveRecord association. I wrote the code as follows: class User < ActiveRecord::Base has_many :messages, :group => "thread", :order => "created_at desc" end It works fine as it returns some records. The problem is that the mysql clause "GROUP BY" ignores NULL values. That makes that records with thread == NULL not to show. ¿Is there a rails option to include NULL values when using :group? Thanks, Pablo -- Posted via http://www.ruby-forum.com/. -- 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 Jan 26, 6:41 pm, Pablo Gonzalez <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m trying to use the :group option in an ActiveRecord association. I > wrote the code as follows: > > class User < ActiveRecord::Base > has_many :messages, :group => "thread", :order => "created_at desc" > end > > It works fine as it returns some records. The problem is that the mysql > clause "GROUP BY" ignores NULL values. That makes that records with > thread == NULL not to show. > > ¿Is there a rails option to include NULL values when using :group? >Given that the underlying DB doesn''t appear to support the operation, I''d say not. Even if it did, the result would be that you''d only get the most recent post with thread == NULL, which doesn''t seem like what you''d want. --Matt Jones -- 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.
I think you''re right. I''ve been looking for that solution and I didn''t find anything really solving it. So I guess I must figure out another approuch, perhaps giving a default value for "thread". Thank you anyway. -- Posted via http://www.ruby-forum.com/. -- 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.