You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
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
The text was updated successfully, but these errors were encountered:
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
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
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:
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
The text was updated successfully, but these errors were encountered: