lundi 6 janvier 2020

Have problem in populating record from partial model definition in Sails JS

In my Sails project A, I have the partial model definition:

User

module.exports = {
    schema: true,
    tableName: 'users',
    primaryKey: 'id',
    attributes: {
        id: {
            columnName: 'id',
            unique: true,
            type: 'number',
            autoIncrement: true
        },
        service_id: {
            type: 'number',
            required: true
        },

In another Sails project B, I have defined the rest of this User model:

User

module.exports = {
    schema: true,
    tableName: 'users',
    primaryKey: 'id',
    attributes: {
        id: {
            columnName: 'id',
            unique: true,
            type: 'number',
            autoIncrement: true
        },
        task_id: {
            type: 'number',
            required: true
        },

and the Task model

module.exports = {
    schema: true,
    tableName: 'tasks',
    primaryKey: 'id',
    attributes: {
        id: {
            columnName: 'id',
            unique: true,
            type: 'number',
            autoIncrement: true
        },
        description: {
            type: 'string',
            required: true
        },

Both project A and B connect to the same mysql database.

I'm writing the acceptance test in project A to list down all the tasks. How could I populate the task model in project A? I got the following error (which is obvious):

Could not populate `tasks`. There is no attribute named `tasks` defined in this model.

Thank you very much.

Aucun commentaire:

Enregistrer un commentaire