Add custom attributes to your models, which doesn't have predefined names but can be created runtime, and still be able to do queries on that data.
Add this to your Gemfile and bundle:
gem 'acts_as_customized_attributes'
class SomeModel
acts_as_customized_attributes
end
This creates the tables "some_model_data_keys" and "some_model_data", where the custom attributes will be stored.
class AddCustomizedAttributesForSomeModel < ActiveRecord::Migration
def up
SomeModel.create_customized_attributes!
end
def down
SomeModel.drop_customized_attributes!
end
end
some_model.update_customized_attributes(my_custom_attribute: 5)
some_model.customized_attributes #=> {:my_custom_attribute => 5}
model.customized_attribute("name_of_key") #=> "some_value"
SomeModelDataKey.where("name LIKE '%facebook%'")
SomeModelData.where("resource_id > 5")
ActiveRecordTransactioner.new do |trans|
models.each do |model|
model.update_customized_attributes_with_args(data: {my_custom_attribute: 5}, transactioner: trans)
end
end
This project uses MIT-LICENSE.