[Rails] Re: Problem with changing from mySql to PostrgreSql with rails
There is still a problem.
@users = User.paginate :joins => :properties ,:select => 'distinct
users.*', :page => params[:page], :order => 'properties.id
DESC',:conditions => ['users.id != 1']
I got this error message.
ActiveRecord::StatementInvalid (PGError: ERROR: for SELECT DISTINCT,
ORDER BY expressions must appear in select list
: SELECT distinct users.* FROM "users" INNER JOIN "properties" ON
properties.user_id = users.id WHERE (users.id != 1) ORDER BY
properties.id DESC LIMIT 10 OFFSET 0):
On Aug 12, 7:25 pm, Hassan Schroeder <hassan.schroe...@gmail.com>
wrote:
> On Thu, Aug 12, 2010 at 4:49 PM, Mohammed Alenazi <vb4...@gmail.com> wrote:
> > @users = User.paginate :joins => :properties ,:select =>
> > 'users.*', :page => params[:page], :order => 'count(properties.id)
> > DESC',:conditions => ['users.id != 1','users.id=properties.user_id']
>
> > this the error message i got
> > misuse of aggregate: count(): SELECT users.* FROM "users" INNER
> > JOIN "properties" ON properties.user_id = users.id WHERE (users.id !=
> > 1) ORDER BY count(properties.id) DESC LIMIT 10 OFFSET 0
>
> No kidding :-) `count(*)` gives you a single number, so you couldn't
> possibly do an ORDER BY with it. Just an ORDER BY properties.id
> should do what you want.
>
> Of course, I have to wonder if this couldn't be done much more neatly
> with a named scope or two, particularly that "users.id != 1" business...
>
> FWIW,
> --
> Hassan Schroeder ------------------------ hassan.schroe...@gmail.com
> twitter: @hassan
--
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home