0
votes

I'm trying to use mixins in Loopback, but it seems I'm making some stupid mistake.

I defined the following mixin in "common/mixins/test.js"

module.exports = function(Model, message) {

    console.log(message);

};

In the "user.json" file I put the following:

{
  "name": "user",
  ... , 

  "mixins":{
      "test":"hello world"
  }
}

I did not change the meta property in the "model-config.json" file , it is

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  ... ,
  "user": {
    "dataSource": "mysql",
    "public": true,
    "options": {
      "emailVerificationRequired": true
    }
  },
...
}

I expect to see "Hello world" when I start the server, but nothing is logged, what am I doing wrong?

1

1 Answers

1
votes

The mixin options should be an object.

Try this please :

"mixins":{
      "Test":{"message": "hello world"}
  }



module.exports = function(Model, options) {

    console.log(options.message);

};