I
I
Ivan Kondratiev2015-12-28 13:57:20
ORM
Ivan Kondratiev, 2015-12-28 13:57:20

Why doesn't relation work in node-orm2?

I use orm2 for nodejs
I use two databases
, there are two models:
Users (the first database)

var Users = db.define( config.database.prefix + 'user', {
            user_id    : { type: 'integer' , key: true},
            user_login : { type: 'text' },
            user_session_token  : { type: 'text' },
            user_mail    : { type: 'text' }
        },
        {
            hooks:
            {
                beforeValidation: function (next) {
                    return next();
                }
            },
            validations:
            {
                userId: [
                    orm.enforce.ranges.length( 1 , 11 , errorsMessage.INVALID_USER_ID ),
                    orm.enforce.patterns.match( /^[0-9]*$/ , '' , errorsMessage.INVALID_USER_ID_STRING )
                ]
            },
            methods:
            {
                serialize: function () {
                    return {
                        user_id    : this.user_id,
                        user_login : this.user_login,
                        user_password  : this.user_password,
                        user_session_token  : { type: 'text' },
                        user_mail    : this.user_mail
                        
                    };
                }
            }
        });


    Users.hasMany('u_chats', db.models.chats,{reverse: 'user_id'});

and second Chats (second database)
var Chats = db.define( config.database.prefix + 'chats', {
            user_id    : { type: 'integer',    size: 11,       required: true },
            createdAt  : { type: 'integer',    size: 11,       required: true },
            typeChat   : { type: 'text',       size: 30,       required: true },
            status     : { type: 'integer',    size: 1,        required: true }
        },
        {
            hooks:
            {
                beforeValidation: function (next) {
                    this.createdAt  =  new Date().getTime();
                    this.typeChat   =  'private';
                    this.status     =  0;

                    return next();
                }
            },
            validations:
            {
                userId: [
                    orm.enforce.ranges.length( 1 , 11 , errorsMessage.INVALID_USER_ID ),
                    orm.enforce.patterns.match( /^[0-9]*$/ , '' , errorsMessage.INVALID_USER_ID_STRING )
                ]
            },
            methods:
            {
                serialize: function () {
                    return {
                        user_id    : this.user_id,
                        createdAt : this.createdAt,
                        typeChat  : this.typeChat,
                        status    : this.status
                    };
                }
            }/*,
            autoFetch : true,
            cache : false*/
        });

Both databases are MySql.
when selecting a user, it gives an error
req.models.gme.gmesite_user.find( { user_session_token: token },function(err,user){
console.log(user);
});


ORMError: Unknown property type: user_id

Tell me what could be wrong!? thank.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question