dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

No primary key #789

Closed ToujouAya closed 3 years ago

ToujouAya commented 7 years ago

I tried to define table without primary key , but I got error message when query in this table, it always show the id column not exist. My table doesn't have id column. How can i query in this table ? Please help me. Thanks

dxg commented 7 years ago

What does your table definition look like? I don't believe ORM will work very well if there's a table with no keys, but you can try explicitly passing in:

ids: []

to the table definition but I'm not sure if it will work.

ToujouAya commented 7 years ago
module.exports = function (orm, db) {
    db.define('user_club', {
        club_id: {type: 'integer'},
        user_id: {type: 'integer'},
        player_state: {type: 'integer'},
        club_chip: {type: 'integer'},
        accept: {type: 'integer'},
        created_at: {type: 'date', time: true},
        updated_at: {type: 'date', time: true}
    });
};

My table is pivot table, i want to save data to pivot table, , i don't want to create associations. Now I can define table model, but I can't update data because it need id column to save. Do you have any idea to update into DB ? I can use raw query to update but I don't know how to use orm model to update