Skip to content

Commit

Permalink
fix(serializer): support reflexive relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminHorn committed Jul 13, 2017
1 parent 4fda519 commit 067283c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function parseRelations (data, relations, options) {

var relationship = null

if (!_.isUndefined(fk)) {
if (!_.isUndefined(fk) && relation.modelTo !== relation.modelFrom) {
if (_.isArray(fk)) {
relationship = makeRelations(toType, fk, options)
} else {
Expand Down
10 changes: 4 additions & 6 deletions test/reflexiveRelationship.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ var request = require('supertest')
var loopback = require('loopback')
var expect = require('chai').expect
var JSONAPIComponent = require('../')
var RSVP = require('rsvp')

var app, Folder;
var app, Folder

describe('reflexive relationship', function () {
beforeEach(function (done) {
Expand Down Expand Up @@ -42,7 +41,6 @@ describe('reflexive relationship', function () {
JSONAPIComponent(app, { restApiRoot: '' })
})


it('should make initial data', function (done) {
request(app).get('/folders').end(function (err, res) {
expect(err).to.equal(null)
Expand All @@ -55,9 +53,9 @@ describe('reflexive relationship', function () {
request(app).get('/folders/1/children').end(function (err, res) {
expect(err).to.equal(null)
expect(res.body.data.length).to.equal(2)
expect(res.body.data[0].relationships.children.data).to.equal(null)
expect(res.body.data[1].relationships.children.data).to.be.an('array')
expect(res.body.data[0].relationships.children.data).to.equal(undefined)
expect(res.body.data[1].relationships.children.data).to.equal(undefined)
done(err)
})
})
})
})

0 comments on commit 067283c

Please sign in to comment.