Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
This demonstrates a bug in how has_many conditions work when the conditions are on a table that is also joined via has_many :through. The object model is: Owner (:name => string) | |-> JoinTable | |-> Target (:name => string, :active => boolean) The problem comes in the named scope on owner-- see spec/models/owner_spec.rb:13 Basically, when it creates the SQL, it looks like: SELECT DISTINCT owners.* FROM `owners` INNER JOIN `join_models` ON `join_models`.`owner_id` = `owners`.`id` AND targets.active = 't' INNER JOIN `targets` ON `targets`.`id` = `join_models`.`target_id` WHERE (targets.name = 'this is active') LIMIT 1 MySQL apparently requires that the targets table be joined before referencing it in the first INNER JOIN clause. This is not true for sqlite3; I don't have postgresql installed right now to check that.