Skip to content

Commit

Permalink
Merge pull request #1353 from mupkoo/camelize-relationship-names
Browse files Browse the repository at this point in the history
Camelize the relationship name before getting the association
  • Loading branch information
samselikoff committed Jul 27, 2018
2 parents 8a0ef54 + 118fb15 commit 2b629dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/route-handlers/base.js
Expand Up @@ -60,7 +60,7 @@ export default class BaseRouteHandler {
Object.keys(json.data.relationships).forEach((relationshipName) => {
let relationship = json.data.relationships[relationshipName];
let modelClass = this.schema.modelClassFor(modelName);
let association = modelClass.associationFor(relationshipName);
let association = modelClass.associationFor(camelize(relationshipName));
let valueForRelationship;

if (association.isPolymorphic) {
Expand Down
Expand Up @@ -145,4 +145,43 @@ module('Integration | Server | Shorthands | Patch with relationships', function(
assert.equal(user.collectibles.length, 0);
});

test('it camelizes relationship names', async function(assert) {
let server = this.newServerWithSchema({
postAuthor: Model.extend({
posts: hasMany()
}),
post: Model.extend({
postAuthor: belongsTo()
})
});

server.loadConfig(function() {
this.patch('/posts/:id');
});

let postAuthor = server.create('post-author');
let post = server.create('post');

await promiseAjax({
method: 'PATCH',
url: `/posts/${post.id}`,
data: JSON.stringify({
data: {
attributes: {
},
relationships: {
'post-author': {
data: {
id: postAuthor.id,
type: 'post-authors'
}
}
}
}
})
});

post.reload();
assert.equal(post.postAuthorId, postAuthor.id, 'relationship gets updated successfully');
});
});

0 comments on commit 2b629dd

Please sign in to comment.