Gareth Adams
2006-Sep-05 09:07 UTC
Eager loading and :order produces ambiguous column error
I''m sure I saw a post about this topic a while ago, but I haven''t been able to find it again. I have this association: has_many :sections, :class_name => "QuestionnaireSection", :order => "position", :dependent => :destroy, :include => :questions but since the Question object has a position column, the query comes back with Mysql::Error: Column ''position'' in order clause is ambiguous: Is there a way to get round this, or do I have to make do with unordered questions? Thanks, Gareth --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Sep-07 13:45 UTC
Re: Eager loading and :order produces ambiguous column error
Gareth Adams wrote:> I''m sure I saw a post about this topic a while ago, but I haven''t been able to > find it again. > > I have this association: > > has_many :sections, :class_name => "QuestionnaireSection", :order => > "position", > :dependent => :destroy, :include => :questions > > but since the Question object has a position column, the query comes back with > > Mysql::Error: Column ''position'' in order clause is ambiguous: > > Is there a way to get round this, or do I have to make do with unordered > questions?:order => ''questionnaire_sections.position'' -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
basically, the problem is the "position" field exists in both tables and it''s not sure which one you want to use. that''s why mark''s suggestion, which specifies which model to use, should work... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- suggest for "ambiguous column" when JOIN associated tables
- ambiguous column name in has_many :through
- Removing column default with a migration
- Patch for #3438: Eager loading doesn''t respect :order of associations
- Error when Eager Loading "Not unique table/alias"