Skip to content

Loading…

Failing tests for RESTAdapter fails to materialize embedded belongsTo associations #523

Closed
wants to merge 2 commits into from

4 participants

@ivanvanderbyl

This is a failing test for #504

Basically this fails as part of the semantics of RESTSerializer are converting the belongsTo key to person_id instead of person which is the key of the embedded object.

@wagenet
Ember.js member

@ivanvanderbyl Can you review and see if this is still an issue on master?

@ivanvanderbyl

On initial tests it still seems to be broken. Has anything changed with regard to embedded: 'load' mappings?

@brennanmceachran

@ivanvanderbyl I think I'm having the same issue... did you ever get around it?

@ivanvanderbyl
@igorT
Ember.js member

Closing due to inactivity.

@igorT igorT closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
2 packages/ember-data/lib/adapters/rest_adapter.js
@@ -321,8 +321,6 @@ DS.RESTAdapter = DS.Adapter.extend({
},
rootForType: function(type) {
- if (type.url) { return type.url; }
-
// use the last part of the name as the URL
var parts = type.toString().split(".");
var name = parts[parts.length - 1];
View
23 packages/ember-data/tests/unit/rest_adapter_test.js
@@ -916,6 +916,29 @@ test("sideloaded data is loaded prior to primary data (to ensure relationship co
});
});
+test("additional data can be embedded within belongsTo associations", function() {
+ var Comment = DS.Model.extend({
+ person: DS.belongsTo(Person),
+ text: DS.attr('string')
+ });
+
+ store.adapter.mappings = {'comments': Comment};
+ store.adapter.serializer.map(Comment, {
+ person: { embedded: 'load' }
+ });
+
+ var comment = store.find(Comment, 1);
+
+ equal(comment.get('text'), 'hello');
+ equal(comment.get('person.name'), "Yehuda Katz", 'embedded belongsTo is loaded correctly');
+
+ ajaxHash.success({
+ comments: [{
+ id: 1, person: {id: 1, name: "Yehuda Katz"}, text: 'hello'
+ }]
+ });
+});
+
test("additional data can be sideloaded with associations in correct order", function() {
var Comment = DS.Model.extend({
person: DS.belongsTo(Person)
Something went wrong with that request. Please try again.