0

This returns the proper amount of records, but, account is only populated in the first record. The query waterline produces is also correct and returns all the associated data for every record. populateAll() has no effect. Swapping .then for .exec has no effect.

Additionally, the one "account" that does show up as an association isn't even the right record.

Am I doing something wrong or is this a bug?

pic

mail_items.find().populate('account').then(function(mail_items) {
    return mail_items;
});

accounts.js

module.exports = {
    tableName : 'accounts',

    attributes : {
        account_id : {
            type : 'int',
            primaryKey : true,
            unique : true
        },

        name : 'string'
    }
};

mail_items.js

module.exports = {
    tableName : 'mail_items',

    attributes : {
        mail_item_id : {
            type : 'int',
            primaryKey : true,
            unique : true
        },

        sender : 'string',

        account : {
            columnName : 'account_id',
            type : 'int',
            model : 'accounts'
        }

    }
};
vusan
  • 5,221
  • 4
  • 46
  • 81
brian
  • 2,745
  • 2
  • 17
  • 33

1 Answers1

0

That's working on mine when associating the table by auto generated id of account model.

account.js

module.exports = {
        name : 'string'
    }
};

mail_items.js

module.exports = {
    //tableName : 'mail_items',
    //table name exactly same to model name
    attributes : {
        mail_item_id : {
            type : 'int',
            primaryKey : true,
            unique : true
        },

        sender : 'string',

        account : {
            //columnName : 'account_id',
            //type : 'int',
            model : 'accounts'
        }

    }
};
vusan
  • 5,221
  • 4
  • 46
  • 81
  • It sure did work. Surely the pk of each table doesn't need to be id... right? If not, I can live with it. – brian Oct 07 '14 at 09:19
  • Yes, But sails is auto generating `id` with primary key and with auto increment property. – vusan Oct 07 '14 at 09:23
  • One reason for not populate model is, there may be no account with the id that linked in mail_items . – vusan Oct 07 '14 at 09:27