Method: RGen::MetamodelBuilder::BuilderExtensions#one_to_one
- Defined in:
- lib/rgen/metamodel_builder/builder_extensions.rb
#one_to_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional one-to-one association between two classes. The class this method is called on is refered to as own_class in the following.
Instances of own_class can use ‘own_role’ to access one associated instance of type ‘target_class’. Instances of ‘target_class’ can use ‘target_role’ to access one associated instance of own_class.
This class method adds the following instance methods where ‘ownRole’ and ‘targetRole’ are to be replaced by the given role names:
own_class#ownRole
own_class#ownRole=(value)
target_class#targetRole
target_class#targetRole=(value)
When an element is set on either side, this element also receives the element is is added to as the new element.
229 230 231 232 233 234 235 236 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 229 def one_to_one(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _ownProps(raw_props).merge({ :name=>target_role, :upperBound=>1, :containment=>false})) props2 = Intermediate::Reference.new(self, _oppositeProps(raw_props).merge({ :name=>own_role, :upperBound=>1, :containment=>false})) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |