has_many through uniq generates invalid sql
Reported by Chad Jolly | January 16th, 2009 @ 08:51 PM
has_many :uniq_replies, :source => :replies, :through => :topics, :uniq => true
pagination generates invalid sql.
from test/console
>> Project.first.uniq_replies.paginate(:page => 1, :per_page => 1)
Project Load (0.3ms) SELECT * FROM "projects" LIMIT 1
Reply Load (0.8ms) SELECT DISTINCT "replies".* FROM "replies" INNER JOIN topics ON replies.topic_id = topics.id WHERE (("topics".project_id = 1)) LIMIT 1 OFFSET 0
SQL (0.0ms) SQLite3::SQLException: near "*": syntax error: SELECT count(DISTINCT "replies".*) AS count_distinct_replies_all FROM "replies" INNER JOIN topics ON replies.topic_id = topics.id WHERE (("topics".project_id = 1))
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "*": syntax error: SELECT count(DISTINCT "replies".*) AS count_distinct_replies_all FROM "replies" INNER JOIN topics ON replies.topic_id = topics.id WHERE (("topics".project_id = 1))
I think the SQL should read: @@@ SQL SELECT DISTINCT "replies".id ...
Comments and changes to this ticket
-
Chad Jolly March 24th, 2009 @ 11:18 PM
Hi Mislav, Just wanted to point out this ticket re: rails 2.3.2
http://rails.lighthouseapp.com/p...
Upon upgrading to rails 2.3.2, my has many through uniq relationships do not work at all, failing with the same error as above.
I wonder if this is an underlying active record issue rather than will_paginate?
-
Mislav March 25th, 2009 @ 12:28 PM
- State changed from open to invalid
Yeah. It's an ActiveRecord issue and it's being actively worked on
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Everyone's favorite Ruby library for pagination of practically anything!