Last active
August 5, 2019 17:59
-
-
Save habdelra/f5c519790afdaf24bf371fa71b1fc464 to your computer and use it in GitHub Desktop.
Card Relationship Polymorphism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In this example we control the types of cards that are allowed in the event relationship | |
// using the "related-cards" relationship that hangs off of the field. | |
{ | |
data: { | |
type: 'cards' | |
id: '@acme/ticket-tools::ticket-card:123', | |
... | |
}, | |
included: [ | |
// This field is a belongs-to of the card in the document data, | |
{ | |
type: 'fields' | |
id: '@acme/ticket-tools::ticket-card::attendee', | |
attributes: { | |
'is-metadata': true, | |
'needed-when-embedded': true | |
}, | |
relationships: { | |
'field-type': { | |
data: { type: 'cards', id: '@cardstack/core-types::belongs-to-field-card' } | |
}, | |
// The idea is that we accept any card whose adopt graph can be traced back (via any path) to the card specified below. In this | |
// example cardstack is providing a core user card that has metadata for a user. Cards | |
// can adopt from @cardstack/user::user-card to provide a user card | |
'related-cards': { | |
// Note that this is intentionally a belongs-to relationship. If there are mulitple interfaces | |
// that can fit in this relationship, they should be encapsulated within a single card. | |
// Experience with the current hub API's `related-types` has shown us that this is better | |
// expressed using a belongs-to instead of a has-many. | |
data: { type: 'cards', id: '@cardstack/user::user-card::v1.0.0' } | |
} | |
} | |
}, | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment