Sunday, 12 March 2017

How to query on shared ids tables on sequelize

I have 4 tables/models that shares ids as primary keys, but for the example I will just show 2

User: {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        allowNull: false
    }
Person: {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        allowNull: false
    },
    name: {
        type: Sequelize.STRING
    }

I am using shared ids, so the person primary key is the primary key of User, it doesn't have autoimcrement. So is there a way to make a join between those 2 tables? I've tried to do something like:

getAll(){
    return User.getAll({
        include: [{
            model:Person,
        }]
    })
}

But since there is no relation it doesn't work. What should I do? Thanks



via ocespedes

No comments:

Post a Comment