dresende / node-orm2

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

Changing unique ID column name error... (PostgreSQL 9.6.1) #771

Closed cwgabel closed 7 years ago

cwgabel commented 7 years ago

Advanced Options (from wiki)

var Person = db.define("person", {
    name : String
}, {
    id   : "person_id"
});

Cannot get this to work (from example, with added modification):

module.exports = function(orm, db) {
    var Message = db.define('message', {
        title: { type: 'text', required: true },
        body: { type: 'text', required: true, big: true },
        createdAt: { type: 'date', required: true, time: true }
    }, {
        **id: "message_id",**
        hooks: {
        ...

Error message:

throw new ORMError("Model defined without any keys", 'BAD_MODEL', { model: opts.table });

This works just fine:

       db.settings.set("properties.primary_key", "message_id");  

Thank you for any help you can provide.

cwgabel commented 7 years ago

Not from wiki, but from http://dresende.github.io/node-orm2/

dxg commented 7 years ago

Try key: true as seen here: https://github.com/dresende/node-orm2#advanced-options

cwgabel commented 7 years ago

http://dresende.github.io/node-orm2/ does not have any mention of this usage:

personId : { type: 'serial', key: true },

which is where I thought documentation resides (given how nice it looks).

So the wiki is the ultimate destination of all node-orm2 documentation?

dxg commented 7 years ago

Yep. Hey @dresende can we remove those docs somehow? Or point them to the main readme?

dresende commented 7 years ago

Done, dropped gh-pages branch ;)