Request Column Name

I have a table containing 2 "unusual" columns - order and like .

The table is replicated in two databases - MySQL and PostgreSQL .

And I need the same application to connect to both databases and use the same query for both:

 PageModel.where("`like` >= ?", params[:liked]) 

This will only work in MySQL .

How to make ActiveRecord to specify a column name?

Something like:

 PageModel.where("%s >= ?" % quote_column_name(:like), params[:liked]) 

I found a method that is useless right now - it just returns the column name without a quote.

http://www.rubydoc.info/docs/rails/3.2.8/ActiveRecord/ConnectionAdapters/Quoting:quote_column_name

Perhaps this is just a placeholder, and is there another way that does this?

+7
source share
1 answer

It depends on one database adapter to another. Thus, each adapter overrides this method with its own definition.

Are you interested in:

 ActiveRecord::Base.connection.quote_column_name "my_column" 
+10
source

All Articles