Skip to content

Commit

Permalink
Always overwrite serializeBelongsTo and serializeHasMany
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmanuel committed Sep 4, 2022
1 parent 136a99e commit 68fab3d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
'ember/no-mixins': 'off',
'ember/no-new-mixins': 'off',
'ember/no-string-prototype-extensions': 'off',
// 'ember/use-ember-data-rfc-395-imports': 'off',
},
overrides: [
// node files
Expand Down
30 changes: 5 additions & 25 deletions addon/serializers/serializer.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import JSONAPISerializer from '@ember-data/serializer/json-api';
import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports

// Should be removed
// https://github.com/emberjs/data/pull/5317
// https://github.com/emberjs/data/pull/5324
const emberDataVersionOlderThan3Point1 = DS.VERSION.match(/^[0-2]\.|^3\.0/);

export default JSONAPISerializer.extend({
// Serialization behavior
// Can be removed (_shouldSerializeHasMany) removed in ember data 3.0.0
// https://github.com/emberjs/data/pull/5290
_shouldSerializeHasMany: function () {
return true;
},
shouldSerializeHasMany: function () {
shouldSerializeHasMany() {
return true;
},

serializeBelongsTo(snapshot, json, relationship) {
if (emberDataVersionOlderThan3Point1) {
this._super.apply(this, arguments);
} else {
this._fixSerializeBelongsTo(snapshot, json, relationship);
}
serializeBelongsTo() {
this._fixSerializeBelongsTo(...arguments);
},

serializeHasMany(snapshot, json, relationship) {
if (emberDataVersionOlderThan3Point1) {
this._super.apply(this, arguments);
} else {
this._fixSerializeHasMany(snapshot, json, relationship);
}
serializeHasMany() {
this._fixSerializeHasMany(...arguments);
},

_fixSerializeBelongsTo(snapshot, json, relationship) {
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/models/post-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { setupTest } from 'ember-qunit';

import { get } from '@ember/object';
import { run } from '@ember/runloop';
import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports

import {
registerConfigEnvironment,
Expand Down Expand Up @@ -196,11 +195,7 @@ module('Unit | Model | post', function (hooks) {
store
.queryRecord('post', { filter: { name: 'Super Name' } })
.then(function (post) {
if (DS.VERSION.match(/^1\.13\./) || DS.VERSION.match(/^2\.[0|1]\./)) {
assert.deepEqual(post, []);
} else {
assert.equal(post, null);
}
assert.equal(post, null);

done();
})
Expand All @@ -209,6 +204,7 @@ module('Unit | Model | post', function (hooks) {
false,
'queryRecord on empty store throws error: ' + error.message
);

done();
});
});
Expand Down

0 comments on commit 68fab3d

Please sign in to comment.