Skip to content

Instantly share code, notes, and snippets.

@sevifives
Created June 15, 2011 16:32
Show Gist options
  • Save sevifives/1027489 to your computer and use it in GitHub Desktop.
Save sevifives/1027489 to your computer and use it in GitHub Desktop.
// ==========================================================================
// Project: FamilyTies.Family
// Copyright: ©2010 My Company, Inc.
// ==========================================================================
/*globals FamilyTies */
/** @class
(Document your Model here)
@extends SC.Record
@version 0.1
*/
FamilyTies.Family = SC.Record.extend(
/** @scope FamilyTies.Family.prototype */ {
// TODO: Add your own code here.
primaryKey: 'id',
name: SC.Record.attr(String, {
isRequired: YES
}),
members: SC.Record.toMany("FamilyTies.Member",{
inverse: "family",
isMaster: YES
})
});
// ==========================================================================
// Project: FamilyTies.Member
// Copyright: ©2010 My Company, Inc.
// ==========================================================================
/*globals FamilyTies */
/** @class
(Document your Model here)
@extends SC.Record
@version 0.1
*/
FamilyTies.Member = SC.Record.extend(
/** @scope FamilyTies.Member.prototype */ {
// TODO: Add your own code here.
primaryKey: 'id',
firstName: SC.Record.attr(String, {
isRequired: YES
}),
lastName: SC.Record.attr(String, {
isRequired: NO
}),
cleanLastName: function (key,val) {
var lastName;
if (val) {
this.set('lastName',val);
lastName = val;
} else {
lastName = this.get('lastName') || this.getPath('family.name');
}
return lastName;
}.property('lastName').cacheable(),
fullName: function() {
var lastName = this.cleanLastName();
return [ this.get('firstName'),lastName ].join(' ');
}.property('firstName','lastName').cacheable(),
family: SC.Record.toOne('FamilyTies.Family',{
inverse: 'members',
isMaster: NO
}),
spouse: SC.Record.toOne('FamilyTies.Member',{
inverse: 'spouse',
isMaster: NO
}),
children: SC.Record.toMany('FamilyTies.Member',{
inverse: 'parents',
isMaster: NO
}),
numberOfChildren: function () {
var retval = this.get('children').length();
return retval;
}.property('children').cacheable(),
parents: SC.Record.toMany('FamilyTies.Member', {
inverse: 'children',
isMaster: YES
})
}) ;
// ==========================================================================
// Project: FamilyTies.Family Fixtures
// Copyright: ©2010 My Company, Inc.
// ==========================================================================
/*globals FamilyTies */
sc_require('models/family');
var fam = [2,4,6,7,8,9];
for (var i=10;i<10000;i++) { fam.push(i); }
FamilyTies.Family.FIXTURES = [
// TODO: Add your data fixtures here.
// All fixture records must have a unique primary key (default 'guid'). See
// the example below.
{
id: 1,
name: 'Dooley',
members: [1,3,5]
},
{
id: 2,
name: 'Jonses',
members: fam
}
];
// ==========================================================================
// Project: FamilyTies.Member Fixtures
// Copyright: ©2010 My Company, Inc.
// ==========================================================================
/*globals FamilyTies */
sc_require('models/member');
FamilyTies.Member.FIXTURES = [];
var kids = [7,8,9];
for (var i=10;i<10000;i++) {
kids.push(i);
FamilyTies.Member.FIXTURES.push( {id: i, firstName: 'Jane'+i,family: [2],parents: [2,6]} );
}
FamilyTies.Member.FIXTURES.push(
// TODO: Add your data fixtures here.
// All fixture records must have a unique primary key (default 'guid'). See
// the example below.
{
id: 1,
firstName: 'Jason',
lastName: 'Dooley',
family: [1]
},
{
id: 2,
firstName: 'Tammy',
lastName: "Johnston",
family: [2],
children: kids
},
{
id: 3,
firstName: 'Julie',
family: [1]
},
{
id: 4,
firstName: 'Billy',
family: [2]
},
{
id: 5,
firstName: 'Flow',
lastName: 'Dooley',
family: [1]
},
{
id: 6,
firstName: 'Jimmy',
family: [2],
children: kids
},
{
id: 7,
firstName: 'Lil\' Jimmy',
family: [2],
parents: [2,6]
},
{
id: 8,
firstName: 'Joyce Jr.',
family: [2],
parents: [2,6]
},
{
id: 9,
firstName: 'Jackie',
family: [2],
parents: [2,6]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment