-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
findRecord for side loading payloads expects not primary records were arrays #3805
Comments
@novtor which serializer are you using? |
@novtor Are you sure this worked in If the sideloading of a single resource should be supported, a fix would be to make sure the value = Ember.makeArray(value);
let { data, included } = this._normalizeArray(store, typeName, value, prop); |
@HeroicEric it is RESTSerializer |
To what versions of ember and ember-data exactly? |
2.0.0 both |
OK, you said that sideloading single resources worked in |
@pangratz , this is the one that I have posted: 1.13.x - "... async: false relationship 'author' on 'book' is not loaded.. " (or something similar) |
@novtor Oh, ok. Now I understand. Thanks for the clarification. |
@HeroicEric , @pangratz thank you for your replies.
"sync loading of the relation 'author' failed on the model 'book', the expected item was abscent in the payload 'authors'" I think the first solution is better but perhaps is more difficult to acheive. The second one will not be very efficient in case of irregular inflectors usage, someone can for example do:
Which will make the second solution to fall into the same problem as described in the issue |
I am also seeing this when trying to upgrade from 1.13.X to 2.3.0. As described, @novtor's jsbin works with 1.13, but change the tags to 2.3.0 and I hit an |
I'm having exactly the same issue.... |
Anyone have any fixes for this? |
Having the exact same issue. It's halted our migration from 1.13 to 2.0. |
As a workaround you could override normalizeFindRecordResponse to change it to the expected export default DS.RESTSerializer.extend({
normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType) {
if ('author' in payload) {
payload.authors = Ember.makeArray(payload.author);
delete payload.author;
}
return this._super(store, primaryModelClass, payload, id, requestType);
}
}); http://emberjs.jsbin.com/cijone/1/edit?html,js,console,output |
Before, `_normalizeArray` would call `forEach` even if the object wasn't an array. We guard against it by using `Ember.makeArray`. fixes emberjs#3805 emberjs#3805
Before, `_normalizeArray` would call `forEach` even if the object wasn't an array. We guard against it by using `Ember.makeArray`. fixes emberjs#3805 emberjs#3805
I have two models, let's say Car and Human. The Car model has a human owner in it:
When I load a car:
I see the following error in the console:
Error occured. Transition: Transition error: TypeError: arrayHash.forEach is not a function
at ember$data$lib$serializers$json$serializer$$default.extend._normalizeArray (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:11413:19)
at ember$data$lib$serializers$json$serializer$$default.extend._normalizeResponse (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:11535:38)
at ember$data$lib$system$serializer$$default.extend.normalizeSingleResponse (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:9738:21)
at ember$data$lib$system$serializer$$default.extend.normalizeFindRecordResponse (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:9595:45)
at ember$data$lib$system$serializer$$default.extend.normalizeResponse (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:9563:53)
at ember$data$lib$system$store$serializer$response$$normalizeResponseHelper (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:3529:43)
at http://localhost:9000/helios/bower_components/ember-data/ember-data.js:3729:25
at Object.Backburner.run (http://localhost:9000/helios/bower_components/ember/ember.debug.js:284:25)
at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:9000/helios/bower_components/ember-data/ember-data.js:9104:33)
at http://localhost:9000/helios/bower_components/ember-data/ember-data.js:3728:22
My payload looks like:
Debugging the ember-data code I saw:
line 11520:
So AFAIU findRecord expects the sideloaded entities were arrays in payload. So it expects something like:
Modifying the payload representation in this manner solves the issue.
It used to work with 1.13.
Ember-data v2.0.0 (2.0.1 also tested)
The text was updated successfully, but these errors were encountered: