This project is archived and is in readonly mode.
has_many :through generates bad SQL during include?
-
...Paul
The problem exists somewhere in the heirarchy of the "exists?" method in active_record/base.rb (or, in active_record/associations/association_collection.rb, where exists? is called from the include? method, passing only the record to be searched for).
I found if I kludged the include? method so the exists call looked like this:
exists?(["#{quoted_table_name}.#{primary_key} = ?", record.id])
Things worked for me, at least in this case. I'm fairly certain that's not a really a good patch, but it confirmed my suspicions that something in that heirarchy isn't properly using the table name space in the query. :P
-
Tarmo Tänav
- State changed from new to invalid
I'm unable to reproduce it, looking at sanitize_sql_hash_for_conditions() which exists?() calls indirectly through expand_id_conditions() it seems that everything should get properly prefixed with a table name.