Class: SC.RelationshipSupport

Provides support for having relationships propagate by data provided by the data source.

This means the following interaction is now valid:

App = { store: SC.Store.create(SC.RelationshipSupport) };

App.Person = SC.Record.extend({
  primaryKey: 'name',

  name: SC.Record.attr(String),

  power: SC.Record.toOne('App.Power', {
    isMaster: NO,
    inverse: 'person'
  })
});

App.Power = SC.Record.extend({
  person: SC.Record.toOne('App.Person', {
    isMaster: YES,
    inverse: 'power'
  })
});

var zan = App.store.createRecord(App.Person, { name: 'Zan' }),
    jayna = App.store.createRecord(App.Person, { name: 'Janya' });

// Wondertwins activate!
var glacier = App.store.loadRecords(App.Power, [{
  guid: 'petunia',  // Shape of...
  person: 'Jayna'
}, {
  guid: 'drizzle',  // Form of...
  person: 'Zan'
}]);

Leveraging this mixin requires your records to be unambiguously defined. Note that this mixin does not take into account record relationship created / destroyed on dataSourceDidComplete, writeAttribute, etc. The only support here is for pushRetrieve, pushDestroy, and loadRecords (under the hood, loadRecord(s) uses pushRetrieve).

This mixin also supports lazily creating records when a related record is pushed in from the store (but it doesn't exist).

This means that the previous example could have been simplified to this:

App.Power = SC.Record.extend({
  person: SC.Record.toOne('App.Person', {
    isMaster: YES,
    lazilyInstantiate: YES,
    inverse: 'power'
  })
});

// Wondertwins activate!
var glacier = App.store.loadRecords(App.Power, [{
  guid: 'petunia',  // Shape of...
  person: 'Jayna'
}, {
  guid: 'drizzle',  // Form of...
  person: 'Zan'
}]);

When the loadRecords call is done, there will be four unmaterialized records in the store, giving the exact same result as the former example.

As a side note, this mixin was developed primarily for use in a real-time backend that provides data to SproutCore as soon as it gets it (no transactions). This means streaming APIs / protocols like the Twitter streaming API or XMPP (an IM protocol) can be codified easier.

Defined in: relationship_support.js

Since:
SproutCore 1.6

Class Methods

Class Method Detail

pushDestroy(original, recordType, id, storeKey)

Disassociate records that are related to the one being destroyed iff this record has isMaster set to YES.

Parameters:
original
recordType
id
storeKey
pushRetrieve(original, recordType, id, dataHash, storeKey, ignore)

Associate records that are added via a pushRetrieve, and update subsequent relationships to ensure that the master-slave relationship is kept intact.

For use cases, see the test for pushRelationships.

The ignore argument is only set to true when adding the inverse relationship (to prevent recursion).

Parameters:
original
recordType
id
dataHash
storeKey
ignore
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:21 GMT-0600 (CST)