Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created May 27, 2016 22:51
Show Gist options
  • Save typeoneerror/eb0ed30d2fd75edce351f5d83b6c591f to your computer and use it in GitHub Desktop.
Save typeoneerror/eb0ed30d2fd75edce351f5d83b6c591f to your computer and use it in GitHub Desktop.
//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
Copy link

kgish commented May 29, 2016

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?

@typeoneerror
Copy link
Author

@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