Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter/Refresh breaks when default database is postgres but current table is in mysql #2321

Closed
dcwieschhaus opened this issue Jun 5, 2015 · 2 comments

Comments

@dcwieschhaus
Copy link

The "Refresh" button in Rails Admin (see attached screenshot) causes an error when you try to filter against a model in a mysql database when the default database for the environment is postgres. The sql statement that is generated when you click the "Refresh" button uses the "ILIKE" expression (because it thinks the current db adapter is postgres) instead of "LIKE" (which mysql needs since it doesn't support "ILIKE").

To replicate the problem, create a small rails 4 project that uses postgres with one model object. After you verify that works, add the mysql2 gem to the project in order to support connecting to a mysql db. Then manually create a second model object in your project that maps to a table in a mysql database, using the establish_connection method in the model to override the project's default postgres database with a mysql database. Here is an example of how to do that:

class Achieve::Company < ActiveRecord::Base
establish_connection "mysqldb_#{Rails.env}"
self.table_name = "companies"
end

In the database.yml file the mysql db config looks like:

mysqldb_development:
adapter: mysql2
database: mydbname
username: mydbusername
password: mydbpw
pool: 5
timeout: 5000

When you do the above, and then introduce Rails Admin, go into rails admin to the table that is in the mysql db and try to do a filter/refresh and you'll get the same error I did.

Here is the screenshot of the rails admin filter/refresh I am referring to:

filter_button_screenshot

As a fix, I was thinking of doing a pull request and introducing a config variable for "force_like" that, if set to true, would always use "LIKE" and never use "ILIKE". The value would default to false to match current functionality. However, if I am missing something, or there is a better idea, I am open to suggestions.

Thanks for your time.

Dan

@dcwieschhaus dcwieschhaus changed the title Filter button breaks when default database is postgres but current table is in mysql Filter/Refresh button breaks when default database is postgres but current table is in mysql Jun 5, 2015
@dcwieschhaus dcwieschhaus changed the title Filter/Refresh button breaks when default database is postgres but current table is in mysql Filter/Refresh breaks when default database is postgres but current table is in mysql Jun 5, 2015
@jlebrijo
Copy link

Did you finally solve this?

I post a similar question in Mailing list: https://groups.google.com/forum/#!topic/rails_admin/VG2UK0GqyCo

@mshibuya
Copy link
Member

mshibuya commented Jun 6, 2019

Merging into #1676.

@mshibuya mshibuya closed this as completed Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants