Forum: Ruby on Rails activerecord issues with rails 3 postgresql

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7498884689bc6ec3e328c0b32f508b40?d=identicon&s=25 amruby (Guest)
on 2012-06-27 16:14
(Received via mailing list)
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?
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2012-06-28 16:42
(Received via mailing list)
On Wednesday, 27 June 2012 10:13:16 UTC-4, amruby wrote:
> when i run this query i got this error
>
> *PG::Error: ERROR:  table name "recommendations" specified more than once*
>
> Why it shows like that?
>

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
This topic is locked and can not be replied to.