drnic/composite_primary_keys — pull request #85 by davedoan (2012-02-09 18:34:11+00:00)
Title: Fix cpk_or_predicate issue when using multiple database connections

CompositePrimaryKeys::Predicates#cpk_or_predicate was making calls to Arel::Node#to_sql without specifying an engine. By default, to_sql falls back to Arel::Table.engine, which is typically set to ActiveRecord::Base. This works fine for most apps that only connect to a single database, but if the model we're generating a predicate for connects to a different database, the table cache lookup fails and ARel/ActiveRecord executes an unnecessary "SHOW TABLES" request every time.

CPK is aware of the table we're generating the predicate for, so this fix supplies the table's engine (and through that, the correct connection) to Arel::Node#to_sql.