RelationshipPayloads Class
Manages the payloads for both sides of a single relationship, across all model instances.
For example, with
const User = DS.Model.extend({ hobbies: DS.hasMany('hobby') });
const Hobby = DS.Model.extend({ user: DS.belongsTo('user') });
let relationshipPayloads = new RelationshipPayloads('user', 'hobbies', 'hobby', 'user');
let userPayload = { data: { id: 1, type: 'user', relationships: { hobbies: { data: [{ id: 2, type: 'hobby', }] } } } };
// here we expect the payload of the individual relationship relationshipPayloads.push('user', 1, 'hobbies', userPayload.data.relationships.hobbies);
relationshipPayloads.get('user', 1, 'hobbies'); relationshipPayloads.get('hobby', 2, 'user');
Methods
Get the payload for the relationship of an individual record.
This might return the raw payload as pushed into the store, or one computed from the payload of the inverse relationship.
Push a relationship payload for an individual record.
This will make the payload available later for both this relationship and its inverse.
Unload the relationship payload for an individual record.
This does not unload the inverse relationship payload.
Returns:
true iff modelName
and relationshipName
refer to the
left hand side of this relationship, as opposed to the right hand side.
Returns:
true iff modelName
and relationshipName
refer to the
right hand side of this relationship, as opposed to the left hand side.
Populate the inverse relationship for relationshipData
.
If relationshipData
is an array (eg because the relationship is hasMany)
this means populate each inverse, otherwise populate only the single
inverse.
Actually add inversePayload
to inverseIdToPayloads
. This is part of
_populateInverse
after we've normalized the case of relationshipData
being either an array or a pojo.
We still have to handle the case that the inverse relationship payload may be an array or pojo.
Remove the relationship in previousPayload
from its inverse(s), because
this relationship payload has just been updated (eg because the same
relationship had multiple payloads pushed before the relationship was
initialized).
Remove id
from its inverse record with id inverseId
. If the inverse
relationship is a belongsTo, this means just setting it to null, if the
inverse relationship is a hasMany, then remove that id from its array of ids.