Hi all, I''ve got an issue where i have a search page that passes a field which is then used as the criteria of the search. Problem is, I''ve set an AR has_many relationship in the model that joins one table to another - both tables have the same column name I''m searching on, so naturally I get an ambiguous error in sql - it doesnt know which column to apply the search to. One solution would be to append the desired table name to the field being passed on in search, like my_database.foo where foo was the ambiguous field. But this doesn''t seem very Rails-ish to my newbie eyes. Is there a better, AR-based way to handle this issue? Best, Peter D Bethke -- 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 Mar 2, 2:34 pm, Peter D Bethke <peter.bet...-ee4meeAH724@public.gmane.org> wrote:> Hi all, > > I''ve got an issue where i have a search page that passes a field which is then used as the criteria of the search. Problem is, I''ve set an AR has_many relationship in the model that joins one table to another - both tables have the same column name I''m searching on, so naturally I get an ambiguous error in sql - it doesnt know which column to apply the search to. > > One solution would be to append the desired table name to the field being passed on in search, like my_database.foo where foo was the ambiguous field. But this doesn''t seem very Rails-ish to my newbie eyes. Is there a better, AR-based way to handle this issue? >How are you specifying your conditions? if you use the hash form of conditions :some_table => (:name => ''bob''), then rails is in general better at figuring out table aliases and so on. Arel is also pretty smart about this, although I don''t recall how much of this is exposed by active record. Fred> Best, > > Peter D Bethke-- 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 2 March 2011 14:34, Peter D Bethke <peter.bethke-ee4meeAH724@public.gmane.org> wrote:> I''ve got an issue where i have a search page that passes a field which is then used as the criteria of the search. Problem is, I''ve set an AR has_many relationship in the model that joins one table to another - both tables have the same column name I''m searching on, so naturally I get an ambiguous error in sql - it doesnt know which column to apply the search to.If you post the code of your search, then maybe we can offer some pointers. But essentially, you need to dis-ambiguate (nice made-up word...) by putting the table name in front of the column name, or by aliasing one of the fields with "AS". -- 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.
Possibly Parallel Threads
- Matrix to "database" -- best practices/efficiency?
- FW: Problems connecting with MySQL using odbcDriverConnect (RODBC package) on Linux
- Resolving ambiguous columns during a join
- suggest for "ambiguous column" when JOIN associated tables
- Eager loading and :order produces ambiguous column error