Module: BelongsToHstore::Association::ClassMethods
- Defined in:
- lib/belongs_to_hstore/association.rb
Instance Method Summary collapse
- #belongs_to_hstore(store_attribute, name, options = {}) ⇒ Object
- #belongs_to_hstore_attributes ⇒ Object
Instance Method Details
#belongs_to_hstore(store_attribute, name, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/belongs_to_hstore/association.rb', line 7 def belongs_to_hstore(store_attribute, name, ={}) @belongs_to_hstore_attributes ||= Set.new key = [:foreign_key] || "#{name}_id" key_type = key.gsub(/_id$/, '_type') store_accessor store_attribute, key.to_s @belongs_to_hstore_attributes.add(key.to_s) if [:polymorphic] store_accessor store_attribute, key_type @belongs_to_hstore_attributes.add(key_type) end belongs_to name, define_singleton_method("where_#{store_attribute}") do || where_hstore(store_attribute, ) end end |
#belongs_to_hstore_attributes ⇒ Object
25 26 27 28 |
# File 'lib/belongs_to_hstore/association.rb', line 25 def belongs_to_hstore_attributes attrs = @belongs_to_hstore_attributes || Set.new superclass.respond_to?(:belongs_to_hstore_attributes) ? superclass.belongs_to_hstore_attributes + attrs : attrs end |