Associations are modeled in Sculptor using References. A reference has a
source DomainObject ('from') and target DomainObject ('to'). Two references
can be connected using the 'opposite' to create a bidirectional association.
When two references are connected the opposite is always set on both
references, pointing to each other.
Let us take a look at
boolean isOneToMany(Reference ref) :
ref.many && ref.opposite != null && !ref.opposite.many;
I think we need an example:
Entity Planet {
- Set<@Moon> moons opposite planet;
}
Entity Moon {
- @Planet planet opposite moons;
}
isOneToMany(Planet.moons) will evaluate to true
Planet.moons.many == true
Planet.moons.opposite == Moon.planet
Moon.planet.many == false
isOneToMany(Moon.planet) will evaluate to false
Moon.planet.many == false
Moon.planet.opposite == Planet.moons
Background: In Sculptor we model associations in a similar way as is done in
EMF Ecore.
/Patrik
Darth wrote:
>
> I am new to this and working with JPA annotations in templates and certain
> annotations go on relations based on if the relation is bidirectional or
> not. However in the templates there is no method or way (I cant find it)
> to figure out a relation's direction.
>
> For example this is used
>
> boolean isOneToMany(Reference ref) :
> ref.many && ref.opposite != null && !ref.opposite.many;
>
> instead of
>
> boolean isOneToMany(Reference ref) :
> !ref.many && ref.opposite != null && ref.opposite.many;
>
>
> As you see that reference is evaluated from the "target" end as opposed to
> the "source" end.
> To check if its a one to many relation, its being checked if its a many to
> one relation and since opposite is checked for nullability, that
> guarantees that from the other end it will be a one to many relation.
>
> But I want to know if that one to many relation is a unidirectional one.
> Which means that opposite == null but it does exist and that
> opposite.opposite != null.
> But I cant do that since that's a null pointer reference.
>
> Any helps in figuring out directionality of relations?
> Thanks
>
--
View this message in context:
http://www.nabble.com/How-to-figure-out-if-a-relation-%28reference%29-is-Bi-Directional--tp18099001s17564p18099555.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Fornax-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fornax-developer