kurko / ember-json-api

JSON API adapter for Ember Data.
MIT License
254 stars 62 forks source link

Adapter.findHasMany error on snapshot.hasMany(relationship.key) #83

Closed green-arrow closed 9 years ago

green-arrow commented 9 years ago

In the findHasMany function, the relationship is being queried in the first line:

var hasManyLoaded = snapshot.hasMany(relationship.key).filter(function(item) { return !item.record.get('currentState.isEmpty'); });

However, it looks like now the result of snapshot.hasMany(relationship.key) is coming back as undefined instead of an empty array, which I believe was the original result when I first wrote that line.

Changing to something like the following should resolve the issue:

var hasMany = snapshot.hasMany(relationship.key);
var hasManyLoaded = hasMany ? hasMany.filter(function(item) {
  return !item.record.get('currentState.isEmpty');
}) : [];
wvteijlingen commented 9 years ago

Yes, this has changed in Ember Data beta17. When no relationship data is available, it returns undefined now instead of an empty array. I had to update this as well to get it working in beta 18.

green-arrow commented 9 years ago

This is fixed in #84

jonkoops commented 9 years ago

It seems this issue was solved by @Asgaroth in his pull request. The specific LOC can be found here. @green-arrow I'm closing this issue and the associated pull request. If I missed anything let me know.

green-arrow commented 9 years ago

@jonkoops Is it possible to get a new release of this cut?I believe this will prevent people from being able to update ember-data.

jonkoops commented 9 years ago

@kurko Could you tag a new release? I am not familiar with the process. Or can I just add a git tag?

kurko commented 9 years ago

@green-arrow @jonkoops so, I pushed 0.5.0 tag to Github.

As for the NPM release, it's really odd. I had released this weak. I guess I either forgot to do the final <enter> to execute the command or there some cache in the interwebz. Anyway, it's there! https://www.npmjs.com/package/ember-json-api

jonkoops commented 9 years ago

Nice. Thanks @kurko