module.exports = function(app) {
var
Account = app.models.Account,
AccountSponsor = app.models.AccountSponsor;
AccountSponsor.belongsTo(Account, {as: 'sponsored', foreignKey: 'sponsoredId'});
AccountSponsor.belongsTo(Account, {as: 'sponsor', foreignKey: 'sponsorId' });
Account.hasMany(Account, {as: 'sponsored', through: AccountSponsor, foreignKey: 'sponsoredId'});
Account.hasMany(Account, {as: 'sponsors', through: AccountSponsor, foreignKey: 'sponsorId'});
Account.create({
"fullName" : "sponsored",
"username" : "sponsored",
"password" : "sponsored"
}, function(err, account){
account.sponsors.create({
"fullName" : "sponsor",
"username" : "sponsor",
"password" : "sponsor"
}, function(err, response){
console.log("SPONSOR: ", response);
});
});
};
Both Accounts where created in the database but only 1 id is stored in the relation model. I tried using the CLI loopback:relation and I get the exact same error