activerecord issues with rails 3 postgresql

22 views
Skip to first unread message

amruby

unread,
Jun 27, 2012, 10:13:16 AM6/27/12
to rubyonra...@googlegroups.com
i have one query 
@recommendations = Recommendation.select('cnames.name,max(recommendations.count)').
                  where('recommendations.skill= ?',@key).
                  order('recommendations.company_id ASC').
                  group('recommendations.company_id').
                  joins('JOIN recommendations ON cnames.id = recommendations.company_id')

when i run this query i got this error

PG::Error: ERROR:  table name "recommendations" specified more than once

Why it shows like that?

Matt Jones

unread,
Jun 28, 2012, 10:40:47 AM6/28/12
to rubyonra...@googlegroups.com
Since you're querying on the Recommendation model, there's already a 'FROM recommendations' clause in the generated query. You probably meant 'cnames' in that joins call.

You'll also run into Postgres's rules about using ungrouped values in the SELECT part; the above query won't be legal even with a correct join.

--Matt Jones
Reply all
Reply to author
Forward
0 new messages