Created
May 27, 2016 22:51
-
-
Save typeoneerror/eb0ed30d2fd75edce351f5d83b6c591f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//mirage/config.js | |
export default function() { | |
this.get('/tenants/current', (schema, request) => { | |
/* | |
returns: | |
{ | |
tenant: { | |
id: 1 | |
profileId: 1 | |
} | |
} | |
expecting: | |
{ | |
tenant: { | |
id: 1, | |
profileId: 1 | |
}, | |
profiles: [{ | |
id: 1 | |
}] | |
} | |
*/ | |
return { | |
tenant: schema.tenants.first() | |
} | |
}); | |
} | |
//mirage/models/tenant.js | |
export default Model.extend({ | |
profile: belongsTo() | |
}); | |
//mirage/models/profile.js | |
export default Model.extend({ | |
}); | |
//mirage/serializers/application.js | |
import { ActiveModelSerializer } from 'ember-cli-mirage'; | |
export default ActiveModelSerializer.extend({ | |
}); | |
//mirage/serializers/tenant.js | |
import ApplicationSerializer from './application'; | |
export default ApplicationSerializer.extend({ | |
include: ['profile'] | |
}); | |
// mirage/scenarios | |
export default function(store) { | |
var profile = store.create('profile'); | |
store.create('tenant', { | |
profile: profile | |
}); | |
} |
@kgish I am creating a profile and a tenant and assigning the profile to the tenant when it is created. with the "include" in the tenant serializer, I am expecting to get the profile data back when I call tenant: schema.tenants.first()
, but I think because this relationship is syncronous in my ember data model, I need to also include the profile data as well. Unsure.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe i can help. Can you please explain in a little bit more detail what you are trying to do and what is going wrong?