rails/rails — Issue #3951: using :finder_sql on a has_many breaks exists? functionality
Author: clst
Created: 2011-12-12 17:55:21+00:00
State: open

When I define a finder_sql on a has_many association and do this:

model1.model3.exists?

I get a SQL-error.

Example:

forum -has many-> topic -has many-> post

using through:

Forum.first.posts.exists?
SELECT 1 FROM "posts" INNER JOIN "topics" ON "posts"."topic_id" = "topics"."id" WHERE "topics"."forum_id" = 1 LIMIT 1
=> true

using finder_sql:

SELECT 1 FROM "posts" WHERE "posts"."forum_id" = 1 LIMIT 1
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.forum_id