Question

I have 2 models User and Player with the association one-to-one:

User.hasOne(Player,{foreignKey:"userid", as : "Player"})

I have the following code:

db.sequelize.transaction(function(t) {
db.User.find(154, {transaction: t}).success(function (user) {

    user.getPlayer({transaction: t}).success(function (player) {
        console.log(player.values);
    }).error(function (error) {
        console.log(error);
    })
}).error(function (error) {
    console.log(error);
})
});

But I never get the player associated with the user in the code above. Is there something wrong with my code?

Was it helpful?

Solution

What do you mean you don't get "the player associated with the user"? Do you mean in your code or in your db?

You need to commit the transaction for it to hit the db.

t.commit().done(function (err) { ... });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top