Skip to content

Commit 8791419

Browse files
author
Joel Alejandro Villarreal Bertoldi
authored
Merge pull request #9 from joelalejandro/fix/issue-8
Now checking value for associationValue
2 parents ceceb7c + 6647a47 commit 8791419

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ function byPrimaryKey(model) {
4040
* @return {Object}
4141
*/
4242
function createRelationshipObject(include, item) {
43-
const relatedModelIdAttribute = include.association.sourceIdentifier; //Object.keys(include.model.attributes).filter(byPrimaryKey(include.model))[0];
43+
const relatedModelIdAttribute = include.association.targetKey;
4444
const associationValue = item[include.as];
45-
if (Array.isArray(associationValue)) {
45+
if (associationValue && Array.isArray(associationValue)) {
4646
const results = [];
4747
associationValue.forEach(function(record) {
4848
const relatedItem = {};
@@ -51,7 +51,7 @@ function createRelationshipObject(include, item) {
5151
results.push(relatedItem);
5252
});
5353
return results;
54-
} else if (typeof associationValue === 'object') {
54+
} else if (associationValue && typeof associationValue === 'object') {
5555
const relatedItem = {};
5656
relatedItem.type = include.model.name;
5757
relatedItem[relatedModelIdAttribute] = associationValue[relatedModelIdAttribute];

0 commit comments

Comments
 (0)