aliatech / loopback-mongo-distinct-mixin

Provide to models the ability to query distinct values from database
MIT License
0 stars 0 forks source link

Error: Model uses unknown mixin: Distinct #1

Closed nodasxiros closed 5 years ago

nodasxiros commented 5 years ago

After following the documentation step by step, I keep getting this error: Error: Model "post" uses unknown mixin: Distinct at MixinProvider.applyMixin (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-datasource-juggler/lib/mixins.js:50:13) at ModelBuilder.defineClass [as define] (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-datasource-juggler/lib/model-builder.js:649:27) at Function.ModelClass.extend (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-datasource-juggler/lib/model-builder.js:447:35) at Registry.createModel (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback/lib/registry.js:122:25) at /Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-boot/lib/executor.js:245:24 at Array.forEach () at defineModels (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-boot/lib/executor.js:229:23) at setupModels (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-boot/lib/executor.js:197:3) at execute (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-boot/lib/executor.js:40:3) at bootLoopBackApp (/Users/nondasxiros/Documents/Workspace/www/theferriescms/node_modules/loopback-boot/index.js:154:3) at Object. (/Users/nondasxiros/Documents/Workspace/www/theferriescms/server/server.js:34:1) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3)

I tried everything but I can't trace down the problem, any help would be much appreciated

Akeri commented 5 years ago

Hello, it should work if you followed the steps, which are pretty much the same as other plugins. Please paste your model json and your model-config.json, maybe I can find something weird.

nodasxiros commented 5 years ago

Model: post.json: { "name": "post", "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "forceId": false, "mixins": { "ObjectidType": { "properties": [ "postId" ] }, "Distinct": true, "Rediscache": {}, "Versioning": true }, "properties": { "name": { "type": "string", "required": true }, "subtitle": { "type": "string" }, "smallDescription": { "type": "string" }, "description": { "type": "string" }, "metaTitle": { "type": "string" }, "metaDescription": { "type": "string" }, "redirectUrl": { "type": "string" }, "trackingUrl": { "type": "string" }, "innerTrackingUrl": { "type": "string" }, "postId": { "type": "string" }, "itemDate": { "type": "date" }, "active": { "type": "boolean", "default": false }, "timeActive": { "type": "boolean", "default": false }, "slug": { "type": "string", "required": true }, "slugActive": { "type": "boolean", "default": true }, "tags": { "type": "array" }, "categories": { "type": "array" }, "authors": { "type": "array" }, "attributes": { "type": "array" }, "type": { "type": "string" }, "continent": { "type": "array" }, "country": { "type": "array" }, "city": { "type": "array" }, "source": { "type": "string" }, "sourceUrl": { "type": "string" }, "interviewee": { "type": "string" }, "gallery": { "type": "array" }, "videoUrl": { "type": "string" }, "videoEmbed": { "type": "string" }, "relItems": { "type": "array" }, "mainPhoto": { "type": "Object" }, "secondaryPhoto": { "type": "Object" }, "lang": { "type": "string", "required": true }, "hits": { "type": "number", "default": 0 }, "createdBy": { "type": "string" }, "updatedBy": { "type": "string" }, "created": { "type": "date" }, "lastUpdated": { "type": "date" } }, "validations": [], "relations": { "createdByUser": { "type": "belongsTo", "model": "user", "foreignKey": "createdBy" }, "updatedByUser": { "type": "belongsTo", "model": "user", "foreignKey": "updatedBy" }, "lists": { "type": "hasMany", "model": "list", "foreignKey": "itemId", "through": "listitem" }, "categoriesList": { "type": "referencesMany", "model": "category", "foreignKey": "categories", "options": { "validate": true, "forceId": false } }, "authorsList": { "type": "referencesMany", "model": "author", "foreignKey": "authors", "options": { "validate": true, "forceId": false } }, "tagsList": { "type": "referencesMany", "model": "tag", "foreignKey": "tags", "options": { "validate": true, "forceId": false } } }, "acls": [ { "accessType": "*", "principalType": "ROLE", "principalId": "$everyone", "permission": "DENY" }, { "accessType": "READ", "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" }, { "accessType": "*", "principalType": "ROLE", "principalId": "$authenticated", "permission": "ALLOW" } ], "methods": { "getPost": { "accepts": { "arg": "filter", "type": "string", "http": { "source": "query" } }, "returns": { "arg": "data", "type": "Post" }, "http": { "verb": "get" } } } }

model-config.json: `{ "_meta": { "sources": [ "loopback/common/models", "loopback/server/models", "../common/models", "./models" ], "mixins": [ "loopback/common/mixins", "loopback/server/mixins", "../node_modules/loopback-mongo-distinct-mixin", "../common/mixins", "./mixins", "../node_modules/loopback-objectid-mixin" ] }, "user": { "dataSource": "ypsilondb", "public": true }, "AccessToken": { "dataSource": "ypsilondb", "public": true, "relations": { "user": { "type": "belongsTo", "model": "user", "foreignKey": "userId" } } }, "ACL": { "dataSource": "ypsilondb", "public": false }, "RoleMapping": { "dataSource": "ypsilondb", "public": true, "options": { "strictObjectIDCoercion": true } }, "Role": { "dataSource": "ypsilondb", "public": true }, "content": { "dataSource": "ypsilondb", "public": true }, "container": { "dataSource": "myStorageDataSource", "public": true }, "sfile": { "dataSource": "ypsilondb", "public": true }, "language": { "dataSource": "ypsilondb", "public": true }, "websetting": { "dataSource": "ypsilondb", "public": true }, "page": { "dataSource": "ypsilondb", "public": true }, "post": { "dataSource": "ypsilondb", "public": true }, "category": { "dataSource": "ypsilondb", "public": true }, "tag": { "dataSource": "ypsilondb", "public": true }, "list": { "dataSource": "ypsilondb", "public": true }, "listitem": { "dataSource": "ypsilondb", "public": true }, "attribute": { "dataSource": "ypsilondb", "public": true }, "menu": { "dataSource": "ypsilondb", "public": true }, "imagesetting": { "dataSource": "ypsilondb", "public": true }, "version": { "dataSource": "ypsilondb", "public": true }, "author": { "dataSource": "ypsilondb", "public": true }, "useronline": { "dataSource": "ypsilondb", "public": true }, "slider": { "dataSource": "ypsilondb", "public": true }

} `

Akeri commented 5 years ago

Problem is in the mixin include path:

"mixins": [ "loopback/common/mixins", "loopback/server/mixins", "../node_modules/loopback-mongo-distinct-mixin", "../common/mixins", "./mixins", "../node_modules/loopback-objectid-mixin" ] }

It should be: "../node_modules/loopback-mongo-distinct-mixin/lib"

Akeri commented 5 years ago

The correct path is: "../node_modules/@aliatech/loopback-mongo-distinct-mixin/lib"

I've just updated the docs, sorry for the inconvenience