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

WIP don't serialize new belongsTo relationship #4500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/serializers/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ const JSONAPISerializer = JSONSerializer.extend({
}

let data = null;
if (belongsTo) {
if (belongsTo && !belongsTo.record.get("isNew")) {
let payloadType;

if (isEnabled("ds-payload-type-hooks")) {
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/serializers/json-api-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,35 @@ test('options are passed to transform for serialization', function(assert) {
env.store.serializerFor('user').serialize(user._createSnapshot());
});

test('a belongsTo relationship with a new record is serialized as { data: null }', function(assert) {
run(function() {
serializer.pushPayload(store, {
data: {
type: 'handles',
id: 1
}
});

let handle = store.peekRecord('handle', 1);

let user = store.createRecord('user');
handle.set('user', user);

let serialized = handle.serialize({ includeId: true });
assert.deepEqual(serialized, {
data: {
type: 'handles',
id: '1',
relationships: {
user: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the whole user relationship be absent instead of data: null?

data: null
}
}
}
});
});
});

testInDebug('JSON warns when combined with EmbeddedRecordsMixin', function(assert) {
assert.expectWarning(function() {
DS.JSONAPISerializer.extend(DS.EmbeddedRecordsMixin).create();
Expand Down