Class: SimplyStored::Couch::HasAndBelongsToMany::Property
- Inherits:
-
AssociationProperty
- Object
- AssociationProperty
- SimplyStored::Couch::HasAndBelongsToMany::Property
- Defined in:
- lib/simply_stored/couch/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.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/simply_stored/couch/has_and_belongs_to_many.rb', line 166 def initialize(owner_clazz, name, = {}) = { :storing_keys => false, :class_name => name.to_s.singularize.camelize, :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.foreign_key.pluralize else [:foreign_key] = owner_clazz.name.singularize.underscore.foreign_key.pluralize 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 |