module BelongsToHstore::Association::ClassMethods
Public Instance Methods
belongs_to_hstore(store_attribute, name, options={})
click to toggle source
# File lib/belongs_to_hstore/association.rb, line 12 def belongs_to_hstore(store_attribute, name, options={}) self.belongs_to_hstore_attributes = self.belongs_to_hstore_attributes.dup key = options[:foreign_key] || "#{name}_id" key_type = key.gsub(/_id$/, '_type') store_accessor store_attribute, key.to_s self.belongs_to_hstore_attributes[key.to_s]= Integer if options[:polymorphic] store_accessor store_attribute, key_type self.belongs_to_hstore_attributes[key_type]= String end belongs_to name, options define_singleton_method("where_#{store_attribute}") do |options| where_hstore(store_attribute, options) end end