Method: Jinx::Dependency#add_dependent_attribute
- Defined in:
- lib/jinx/metadata/dependency.rb
#add_dependent_attribute(attribute, *flags) ⇒ Object
Adds the given attribute as a dependent.
If the attribute inverse is not a collection, then the attribute writer is modified to delegate to the dependent owner writer. This enforces referential integrity by ensuring that the following post-condition holds:
-
owner.attribute.inverse == owner
where:
-
owner is an instance this attribute’s declaring class
-
inverse is the owner inverse attribute defined in the dependent class
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jinx/metadata/dependency.rb', line 24 def add_dependent_attribute(attribute, *flags) prop = property(attribute) logger.debug { "Marking #{qp}.#{attribute} as a dependent attribute of type #{prop.type.qp}..." } flags << :dependent unless flags.include?(:dependent) prop.qualify(*flags) inverse = prop.inverse inv_type = prop.type # example: Parent.add_dependent_attribute(:children) with inverse :parent calls the following: # Child.add_owner(Parent, :children, :parent) inv_type.add_owner(self, attribute, inverse) logger.debug { "Marked #{qp}.#{attribute} as a dependent attribute with inverse #{inv_type.qp}#{inverse}." } end |