Skip to content

Instantly share code, notes, and snippets.

@benbabics
Last active January 25, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbabics/8f0b6c133d003a31a75dfff1af25ba01 to your computer and use it in GitHub Desktop.
Save benbabics/8f0b6c133d003a31a75dfff1af25ba01 to your computer and use it in GitHub Desktop.
export default Model.extend({
users: hasMany( 'user', { inverse: 'company' } ),
usersBilling: hasMany( 'user', { inverse: 'billingCompany' } ),
});
export default Model.extend({
company: belongsTo( 'account' ),
billingCompany: belongsTo( 'account' )
});
// result (when serializers-user's `include` is commented out)
{
user: {
id: "1",
billingCompanyId: "4",
companyId: "1"
}
}
// result (when serializers-user's `include` exists)
{
user: {
id: "1",
billingCompanyId: "4",
account: { name: 'State of Maine' }
}
}
// expected
{
user: {
id: "1",
billingCompany: { name: 'Washington County' },
company: { name: 'State of Maine' }
}
}
const accounts = [
server.create( 'account', { name: 'State of Maine' } ),
server.create( 'account', { name: 'Aroostook County' } ),
server.create( 'account', { name: 'Cumberland County' } ),
server.create( 'account', { name: 'Washington County' } ),
server.create( 'account', { name: 'Androscoggin County' } )
];
server.create('user', {
company: accounts[0],
billingCompany: accounts[3]
});
export default ApplicationSerializer.extend({
include: [ 'company', 'billingCompany' ]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment