Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasMany, belongsTo inconsistent about adapter vs serializer #4954

Closed
jamesarosen opened this issue Apr 28, 2017 · 0 comments · Fixed by #5410
Closed

hasMany, belongsTo inconsistent about adapter vs serializer #4954

jamesarosen opened this issue Apr 28, 2017 · 0 comments · Fixed by #5410

Comments

@jamesarosen
Copy link

jamesarosen commented Apr 28, 2017

Summary

In a hasMany or belongsTo relationship, fetching the associated record(s) will use the source adapter and the foreign serializer.

Example

I have two models: Person and Group:

// app/models/group.js:
people: DS.hasMany('person')

// app/models/person.js:
group: DS.belongsTo('group')

The Person API is classic JSON. The Group API is JSON-API. So I declare adapters and serializers accordingly:

// app/adapters/group.js
import DS from 'ember-data';
export default DS.JSONAPIAdapter;

// app/adapters/person.js
import ActiveModelAdapter from 'active-model-adapter';
export default ActiveModelAdapter;

// app/serializers/group.js
import DS from 'ember-data';
export default DS.JSONAPISerializer;

// app/serializers/person.js
import { ActiveModelSerializer } from 'active-model-adapter';
export default ActiveModelSerializer;

If I do a store.findAll('person') or a store.find('group', 178), this works great.

But if I do person.get('group') or group.get('people'), this breaks terribly. The problem is that person.get('group') uses adapter:person (not adapter:group), but serializer:group. Thus, it's receiving active-model-style JSON, but expecting JSON-API.

If I do store.query('group', { include: 'people' }), it breaks in a different way. The JSON-API response for groups comes back with JSON-API documents for the people. It passes these documents to serizlier:person, which expects active-model-style JSON documents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant