Skip to content

Instantly share code, notes, and snippets.

@erichocean
Created December 17, 2010 20:04
Show Gist options
  • Save erichocean/745609 to your computer and use it in GitHub Desktop.
Save erichocean/745609 to your computer and use it in GitHub Desktop.
query-based to many relationship
messages: SC.RecordAttribute.create({
toType: function(record, key, value) {
var ary = record._messages ;
if (!ary) {
console.log('creating a messages query for Mailbox[%@]'.fmt(record.get('guid')));
CoreOI.Record.messages++ ;
ary = record._messages = record.get('store').findAll(SC.Query.create({
recordType: 'CoreOI.Message',
conditions: "mailbox = %@",
parameters: [record],
orderBy: "dateSent DESC"
}));
} else {
console.log('verifying freshness of messages query for Mailbox[%@]'.fmt(record.get('guid')));
ary.refresh() ;
}
return ary ;
}
}),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment