Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationship: many to many #4

Open
DavidSouther opened this issue Apr 20, 2015 · 0 comments
Open

Relationship: many to many #4

DavidSouther opened this issue Apr 20, 2015 · 0 comments

Comments

@DavidSouther
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant