#261 ✓invalid
Chad Jolly

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

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.

New-ticket Create new ticket

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!

People watching this ticket

Attachments

Pages