Class: SimplyCouch::Model::HasAndBelongsToMany::Property
- Inherits:
-
AssociationProperty
- Object
- AssociationProperty
- SimplyCouch::Model::HasAndBelongsToMany::Property
- Defined in:
- lib/simply_couch/model/has_and_belongs_to_many.rb
Instance Attribute Summary
Attributes inherited from AssociationProperty
Instance Method Summary collapse
-
#initialize(owner_clazz, name, options = {}) ⇒ Property
constructor
A new instance of Property.
Methods inherited from AssociationProperty
#association?, #build, #dirty?, #serialize, #supports_dirty?
Constructor Details
#initialize(owner_clazz, name, options = {}) ⇒ Property
Returns a new instance of Property.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/simply_couch/model/has_and_belongs_to_many.rb', line 187 def initialize(owner_clazz, name, = {}) = { :storing_keys => false, :class_name => owner_clazz.find_association_class_name(name), :foreign_key => nil, }.update() # there is only one pair of foreign_keys and it usualy the name of the class not storing the keys if [:foreign_key].blank? if [:storing_keys] [:foreign_key] = [:class_name].singularize.underscore.sub(/.*\//, '').foreign_key.pluralize.to_sym else [:foreign_key] = owner_clazz.name.singularize.underscore.sub(/.*\//, '').foreign_key.pluralize.to_sym end end [:class_storing_keys] = [:storing_keys] ? owner_clazz.name : [:class_name] @name, @options = name, .assert_valid_keys(:class_name, :foreign_key, :storing_keys, :class_storing_keys) owner_clazz.class_eval do _define_cache_accessors(name, ) define_has_and_belongs_to_many_property([:foreign_key]) if [:storing_keys] define_has_and_belongs_to_many_views(name, ) define_has_and_belongs_to_many_getter(name, ) define_has_and_belongs_to_many_setter_add(name, ) define_has_and_belongs_to_many_setter_remove(name, ) define_has_and_belongs_to_many_setter_remove_all(name, ) define_has_and_belongs_to_many_count(name, ) define_has_and_belongs_to_many_after_destroy_cleanup(name, ) end end |