gregbell/active_admin — Issue #625: filter on field within another database
Author: timcreatewell
Created: 2011-10-15 02:55:44+00:00
State: open

Hi there,

I've unfortunately come across an issue with active admin (which otherwise has been absolutely awesome so far) that I'm not sure how to resolve with regards to filtering on model attributes.

The situation is this: I have a table in one db - e.g "db1_dev.crew_application" and also another table in another db that is joined to this table by a "belongs_to" - e.g. "db2_dev.contact" .

"db1_dev" is the main database for my project, so within the model for the "db2_dev.contact" table I have the necessary establish_connection "db2_#{Rails.env}" . With this in place my rails app is chugging along just nicely with cross-database joins operating as expected.

Except I'm now trying to (for the active admin page for "db1.crew_application" create a filter on an attribute (first name) within "db2_dev.contact". I am doing this by declaring:

filter :contact_first_name, :as => :string, :label => "First Name"

This renders the filter just nicely, but when I try to run the filter I get the following error:

Mysql2::Error: Table 'db1_dev.contact' doesn't exist: SELECT COUNT(DISTINCT count_column) FROM (SELECT `crew_application`.`id` AS count_column FROM `crew_application` LEFT OUTER JOIN `contact` ON `contact`.`id` = `crew_application`.`contact_id` WHERE (`contact`.`first_name` LIKE '%Gandalf%') LIMIT 30 OFFSET 0) subquery_for_count

So, obviously the query isn't recognising that the table "contact" is actually in a totally different database to "crew_application"...

Is there something that I've neglected to do to make this work, or does anyone have any ideas how I could get this working?

Thanks in advance,
Tim.