how ruby model attributes or column_names belong class (that is, have column type in database)?
e.g.: -get column_names belonging class activesupport::timewithzone following model having fields: :id :order_id string :slot_id integer :delivery_date timewithzone :packed_date timewithzone :created_at timewithzone :updated_at timewithzone -output: ['created_at','updated_at','delivery_date','packed_date']
for rails 4 postgres try this:
modelname.columns.select {|col| col.sql_type == "timestamp time zone" }.map(&:name)
for rails 3 mysql try this:
modelname.arel_table.columns.select {|col| col.class == arel::attributes::time }.map(&:name)
Comments
Post a Comment