-
Notifications
You must be signed in to change notification settings - Fork 1
Description
The has_many relationship type will find many entities of RemoteType where RemoteType[RelationshipKey] === LocalType[RelationshipKey]. This implicitly forces a one to many / many to one relationship - any RemoteType may relate to one and only one LocalType. To implement Many to Many relationships, developers must introduce an implicit helper entity.
With the addition of list properties in f2edc, we can implement a Many to Many type by putting a list of RemoteType[RelationshipKey] in LocalType[RelationshipKey: <List>. For a practical example, this would mean creating Blog::tags as a many to many relationship, and a Blog::tag_id as a List property to maintain the list of Tag ids.
How do we represent this?
Overall Structure
{
"entities": {
"Foo": {
"key": "foo_id",
"properties": {
"foo_id": {
"type": "string"
},
"bar_ids": {
"type": "list"
}
},
"relationships": {
"bars": {
"type": "has_list",
"property": "bar_ids",
"to": {
"type": "bar",
"property": "bar_id"
}
}
}
},
"Bar": {
"key": "bar_id",
"properties": {
"bar_id": {
"type": "string"
}
}
}
}
}We have two entities, Foo and Bar. Foo will have many Bars, via foo.bars, with the list of bar_ids in Foo::bar_ids. The question is how to declare this, in the relationship "type". I see three options: has_list and many_many, both introducing new type options. The third option is a bit more compact, but uses non-local information: has_many, and when the local property is type: "list" use the many/many logic.
Introduce new type, and call it has_list or has_many, or override an existing type?