0

I'm starting with koa and waterline ORM. I have a problem when I try to use "testFucntion" method from this waterline model from my controller:

"use strict";
//https://github.com/balderdashy/waterline-docs
var Waterline = require('waterline');
var bcrypt = require('bcrypt');

var User = Waterline.Collection.extend({
    identity: 'user',
    connection: 'default',
    attributes: {
        username: {
            type: 'string',
            required: true,
        },
        password: {
            type: 'string',
            minLength: 6,
            maxLength: 21
        }
    },

    //test function
    testFucntion: function *(params) {
        ...
        console.log('inside');
    }
});

The code I'm using to execute the method is :

function *(){
    var params= this.request.body
    var userModel = this.models.user;
    var result = yield userModel.testFucntion(params)
}

I dont know if this kind of functions are public and how can I use it from outside...

Travis Webb
  • 14,688
  • 7
  • 55
  • 109

1 Answers1

0

The custom methods on the model need to go under the attributes node. Where you have it is for the model specification and event lifecycle methods (we all make that mistake at first).

Andrew Eddie
  • 988
  • 6
  • 15