|
Basic relationships to zero or more other node entities are either modeled with a Set, List, Collection, or Iterable class, with the referenced node entity as the collection type. The use of a Set, List, or Collection class signifies that the field is modifiable from the containing node's perspective, while an Iterable class indicates this should be treated as read-only.
Based on the contained node entity class type and its annotations, SDN will be able to work out that your intention is for this field to represent a basic relationship. If, however, you'd like to overwrite any of the defaults inferred, you can add a @RelatedTo annotation. The friends relationships (#2) between users is an example. Note how in this case we added the @RelatedTo annotation to specify the underlying Neo4j relationship type as IS_FRIEND_OF rather than the default value that SDN would have inferred if it were not there—that is, the name of the referenced field, friends.
Rich relationships, defined as being represented by an underlying Neo4j relationship with associated properties, are also modeled with the same Collection class as basic relationships.
In this case, however, the type of the contained entity in the collection is a relationship entity rather than a node entity. To recap, a relationship entity represents the underlying Neo4j relationship along with any associated properties that were also modeled in the entity. This provides a neat way to access the rich information on the relationship itself, while still being able to get to the entity or entities on the other end. As with basic relationships, without any annotations, SDN can work out that you're creating such references based solely on the fact that the type of class contained in the collection has been defined as a relationship entity. Again, if you wish to override any of these relationship defaults assumed by SDN, you can apply the @RelatedToVia annotation. As you've already seen, the views field reference (#3) representing the relationship between a User and a Movie is a good example here as the additional stars rating serves to enhance the information of the relationship between these two entities.
Notice the different Collection class used for the views property in the case of the User and Movie nodes, namely Setand Iterable, respectively. This means that the views property can be modified from the User node perspective but not from the Movie node. Conceptually, users rate movies, movies don't apply ratings to users!
|
|