0

I'm currently working on an SailsJS app. I started to work with version 0.10.5 and implemented lots of models with inheritance between them. All was working fine.

Today, I decided to update my SailsJS project to version 0.11.0. I've read that the simplest way to do that was to update all SailsJS files with npm, then create a new project and finally copy all models, controllers, etc to the freshly created project. This is what I've done so far.

I'm now encountering an issue each time I try to lift my project :

/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82
    throw new Error('Trying to access a collection ' + collection + ' that is 
          ^
Error: Trying to access a collection series that is not defined.
    at ForeignKeys.findPrimaryKey (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82:11)
    at ForeignKeys.replaceKeys (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:53:27)
    at new ForeignKeys (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:30:10)
    at new module.exports (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema.js:30:17)
    at Waterline.initialize (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline.js:107:17)
    at buildORM (/usr/local/lib/node_modules/sails/lib/hooks/orm/build-orm.js:52:15)
    at Array.async.auto.instantiatedCollections [as 1] (/usr/local/lib/node_modules/sails/lib/hooks/orm/index.js:203:11)
    at listener (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:493:46)
    at /usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:444:17
    at Array.forEach (native)
    at _each (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:46:24)
    at Object.taskComplete (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:443:13)
    at processImmediate [as _immediateCallback] (timers.js:345:15)

There are my models :

/api/services/OrthancObject.js

module.exports = {
    attributes:
    {
        ID:
        {
            type: 'STRING',
            primaryKey: true,
            required: true
        },
        Type:
        {
            type: 'STRING',
            required: true
        },
        MainDicomTags:
        {
            type: 'JSON',
            required: true
        }
    }
}

/api/services/OrthancMutableObject.js

var OrthancObject = require('./OrthancObject.js');
module.exports = _.merge(_.cloneDeep(OrthancObject),
{
    attributes:
    {
        IsStable:
        {
            type: 'BOOLEAN',
            required: true
        },
        LastUpdate:
        {
            type: 'DATETIME',
            required: true
        }
    }
});

/api/models/Patient.js

var OrthancMutableObject = require('../services/OrthancMutableObject.js');
    module.exports = _.merge(_.cloneDeep(OrthancMutableObject),
    {
        attributes:
        {
            Studies:
            {
                collection: 'Study',
                via: 'ParentPatient',
                required: true
            }
        }
    });

/api/models/Study.js

var OrthancMutableObject = require('../services/OrthancMutableObject.js');
module.exports = _.merge(_.cloneDeep(OrthancMutableObject),
{
    attributes:
    {
        ParentPatient:
        {
            model: 'Patient',
            required: true
        },
        Series:
        {
            collection: 'Series',
            via: 'ParentStudy',
            required: true
        }
    }
});

/api/models/Series.js

var OrthancMutableObject = require('../services/OrthancMutableObject.js');
module.exports = _.merge(_.cloneDeep(OrthancMutableObject),
{
    attributes:
    {
        ExpectedNumberOfInstances:
        {
            type: 'INTEGER'
        },
        Instances:
        {
            collection: 'Instance',
            via: 'ParentSeries',
            required: true
        },
        ParentStudy:
        {
            model: 'Study',
            required: true
        },
        Status:
        {
            type: 'STRING'
        }
    }
});

/api/models/Instance.js

var OrthancObject = require('../services/OrthancObject.js');
module.exports = _.merge(_.cloneDeep(OrthancObject),
{
    attributes:
    {
        FileSize:
        {
            type: 'INTEGER',
            required: true
        },
        FileUuid:
        {
            type: 'INTEGER',
            required: true
        },
        IndexInSeries:
        {
            type: 'INTEGER',
            required: true
        },
        ParentSeries:
        {
            model: 'Series'
        }
    }
});

Could you explain me what I am doing wrong ? I can't get why it isn't working anymore (reminder: it was working well in v 0.10.5).

Thanks for reading, Have a nice day :)

fwoelffel
  • 412
  • 7
  • 16

2 Answers2

1

All your models should be in api/models. Nowhere else. If you just follow convention, everything will work.

If you have "base" models that you extend from, just put them outside of api/ altogether if you don't want tables created for them in the database.

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
  • You're right. I was following this http://irlnathan.github.io/sailscasts/blog/2013/09/15/sailscasts-answers-ep1-question-about-using-a-service-to-allow-inheritance-in-a-model/ But it looks outdated now – fwoelffel Mar 25 '15 at 16:47
  • Ha, yea that's a year and a half old at this point. I guess they should have a disclaimer on there – Travis Webb Mar 25 '15 at 16:48
0

Ok guys. I found the solution : I had to move all my base models from /api/services to /api/base. Now it works but I don't really know why. Maybe SailsJS doesn't play its magic inside /api/services anymore since last update.

fwoelffel
  • 412
  • 7
  • 16