I am trying to make a one to many links where a user can put in multiple addresses after their name. For example the data can look like this:
name: "Robert Cane"
address:
location: 555 Fake Street
description: Primary address
is_residence: True
location: 123 Foobar Ave.
description: Mailing address
is_residence: False
There are two ways I can do this. Is it better to setup the database this way (similar to writing tables for SQL databases):
type Address {
required property location -> str;
description -> str;
is_residence ->bool;
}
type Person {
required property name -> str;
required multi link address -> Address{
constraint exclusive;
}
}
or this way using the properties inside the multi link (similar to a relationship inside a Graph database). Also note that this is a single, optional entry according to the docs:
type Address {
required property location -> str;
is_residence -> bool;
}
type Person {
required property name -> str;
required multi link address -> Address{
property description -> str;
constraint exclusive;
}
}
My question is are there best practices to do this? Is doing it one way more advantageous in query speed over the other?
Given that "address" is a one-to-many link there is no meaningful distinction between a property of the link and a property of the target object ("Address" in this case) because every target can only be linked at most once. In this situation using a link property is not necessary and not advisable because the same property on the "Address" is going to be easier to access, update, cast into JSON, etc.
Usually you want to use link properties with many-to-many links. In that case there is a significant distinction between the relationship described by the link and the object being linked. You can have multiple different links with different link property values linking to the same target object.
So if you wanted to re-use the same "Address" object for multiple people, then you'd want to put "description" into a link property (what's "home" for one Person is "grandma's house" for another). Incidentally, this scenario makes sense if you expect addresses to be shared and avoiding duplication is useful both for consistency of data and for performance.