<NME> belongsToPolymorphic.test.js
<BEF> 'use strict'

var request = require('supertest')
var loopback = require('loopback')
var app;
var ds;
var Post;
var File;

describe('loopback json api belongsTo polymorphic relationships', function () {
  beforeEach(function () {
describe('loopback json api belongsTo polymorphic relationships', function () {
  beforeEach(function () {
    app = loopback()
    app.set('legacyExplorer', false)
    ds = loopback.createDataSource('memory')
      title: String,
      content: String
    });
    Post.settings.plural = 'posts';
    app.model(Post);

    File = ds.createModel('file', {
      id: {type: Number, id: true},
      fileName: String,
      parentId: Number,
      parentType: String
    });
    File.settings.plural = 'files';
    File.belongsTo('parent', {
      polymorphic: {
        foreignKey: 'parentId',
        discriminator: 'parentType'
      }
    });
    app.model(File);

    app.use(loopback.rest());
    JSONAPIComponent(app);
    app.use(loopback.rest())
    JSONAPIComponent(app)
  })

  describe('File belonging to a Post', function () {
    beforeEach(function (done) {
        content: 'Content'
      }, function (err, post) {
        expect(err).to.equal(null);
        File.create({
          fileName: 'blah.jpg',
          parentId: post.id,
          parentType: 'post'
          FileModel.create(
            {
    });

    it('should have a relationship to Post', function (done) {
      request(app).get('/files/1')
        .end(function (err, res) {
          expect(err).to.equal(null);
          expect(res.body).to.not.have.key('errors');
      )
    })

    });

    it('should return the Post that this file belongs to when included flag is present', function (done) {
      request(app).get('/files/1?include=parent')
        .end(function (err, res) {
          expect(err).to.equal(null);
          expect(res.body).to.not.have.key('errors');
    })

    it(
      'should return the Post that this file belongs to when included flag is present',
      function (done) {
    });

    it('should return the Post that this file belongs to when following the relationship link', function (done) {
      request(app).get('/files/1')
        .end(function (err, res) {
          expect(err).to.equal(null);
          expect(res.body).to.not.have.key('errors');
            expect(res.body.included[0].id).to.equal('1')
            done()
          })
      }
    )

    it(
      'should return the Post that this file belongs to when following the relationship link',
      function (done) {
        request(app).get('/fileModels/1').end(function (err, res) {
          expect(err).to.equal(null)
          expect(res.body).to.not.have.key('errors')
          request(app)
            .get(
              res.body.data.relationships.parent.links.related.split('api')[1]
            )
            .end(function (err, res) {
              expect(err).to.equal(null)
              expect(res.body).to.not.have.key('errors')
              expect(res.body.data.type).to.equal('posts')
              expect(res.body.data.id).to.equal('1')
              done()
            })
        })
      }
    )
  })
})

<MSG> Change model naming away from reserved 'file'

<DFF> @@ -5,7 +5,7 @@ var JSONAPIComponent = require('../');
 var app;
 var ds;
 var Post;
-var File;
+var FileModel;
 
 describe('loopback json api belongsTo polymorphic relationships', function () {
   beforeEach(function () {
@@ -17,23 +17,21 @@ describe('loopback json api belongsTo polymorphic relationships', function () {
       title: String,
       content: String
     });
-    Post.settings.plural = 'posts';
     app.model(Post);
 
-    File = ds.createModel('file', {
+    FileModel = ds.createModel('fileModel', {
       id: {type: Number, id: true},
       fileName: String,
       parentId: Number,
       parentType: String
     });
-    File.settings.plural = 'files';
-    File.belongsTo('parent', {
+    FileModel.belongsTo('parent', {
       polymorphic: {
         foreignKey: 'parentId',
         discriminator: 'parentType'
       }
     });
-    app.model(File);
+    app.model(FileModel);
 
     app.use(loopback.rest());
     JSONAPIComponent(app);
@@ -46,7 +44,7 @@ describe('loopback json api belongsTo polymorphic relationships', function () {
         content: 'Content'
       }, function (err, post) {
         expect(err).to.equal(null);
-        File.create({
+        FileModel.create({
           fileName: 'blah.jpg',
           parentId: post.id,
           parentType: 'post'
@@ -55,7 +53,7 @@ describe('loopback json api belongsTo polymorphic relationships', function () {
     });
 
     it('should have a relationship to Post', function (done) {
-      request(app).get('/files/1')
+      request(app).get('/fileModels/1')
         .end(function (err, res) {
           expect(err).to.equal(null);
           expect(res.body).to.not.have.key('errors');
@@ -65,7 +63,7 @@ describe('loopback json api belongsTo polymorphic relationships', function () {
     });
 
     it('should return the Post that this file belongs to when included flag is present', function (done) {
-      request(app).get('/files/1?include=parent')
+      request(app).get('/fileModels/1?include=parent')
         .end(function (err, res) {
           expect(err).to.equal(null);
           expect(res.body).to.not.have.key('errors');
@@ -77,7 +75,7 @@ describe('loopback json api belongsTo polymorphic relationships', function () {
     });
 
     it('should return the Post that this file belongs to when following the relationship link', function (done) {
-      request(app).get('/files/1')
+      request(app).get('/fileModels/1')
         .end(function (err, res) {
           expect(err).to.equal(null);
           expect(res.body).to.not.have.key('errors');

Change model naming away from reserved 'file'