Skip to content

Instantly share code, notes, and snippets.

@bushxnyc
Created October 26, 2011 01:25
Show Gist options
  • Save bushxnyc/1315133 to your computer and use it in GitHub Desktop.
Save bushxnyc/1315133 to your computer and use it in GitHub Desktop.
oneTomany Relationship in Sproutcore
App.Category = SC.Record.extend({
name: SC.Record.attr(String),
parent: SC.Record.toOne('App.Category'),
lft: SC.Record.attr(Number),
rgt: SC.Record.attr(Number),
itemType: SC.Record.attr(String),
listings: SC.Record.toMany('App.Listing', {inverse: "category"}),
//Tree Properties
treeItemIsExpanded: NO,
treeItemChildren: function(){
return App.store.find(SC.Query.local(App.Category,
"parent_id = {categoryId}", {
categoryId: this.get('guid'),
orderBy: "name ASC"
}))
}.property('guid').cacheable()
});
App.Listing = SC.Record.extend({
title: SC.Record.attr(String),
category: SC.Record.toOne("App.Category", {inverse: "listings"}),
status: SC.Record.attr(Number),
value: SC.Record.attr(String),
type: SC.Record.attr(String),
description: SC.Record.attr(String)
});
Csquare.Listing.FIXTURES = [
{
guid: 1,
title: "The first of many posts",
category: [10],
description: "Another test of my Herculian Strength",
type: "Sale",
status: 2,
value: 10
}
]
Csquare.Category.FIXTURES = [
{
guid: 10,
name: "For Sale",
status: 2,
lft: 0,
rgt: 0,
itemType: "sale",
parent_id: 0
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment