如果我要在 api-server 应用程序的 loopbackjs 中定义一个名为 User 的模型,我该怎么办?
How should I do if I am going to define a model called User in loopbackjs from an api-server application?
我创建了一个 api-server loopbackjs 应用程序,我想定义一个名为 User 的模型,它具有 与内置的完全不同的属性一个。所以当我 运行 slc loopback:model
时,它会抛出如下错误。
events.js:163
throw er; // Unhandled 'error' event
^
ValidationError: The `ModelDefinition` instance is not valid. Details: `name` is not unique (value: "User").
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:326:12
at ModelConstructor.<anonymous> (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:511:13)
at ModelConstructor.next (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/hooks.js:82:12)
at done (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:508:25)
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:586:7
at ModelConstructor.<anonymous> (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:380:5)
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:1985:11
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:396:17
at done (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:167:19)
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:40:16
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:393:21
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:1962:17
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
如果我真的需要在我的应用程序中调用一个名为 User 的模型,我真的很感激任何人都可以阐明这个问题。
loopback 带有一些内置模型;-) User 就是其中之一。
以小写字母(用户)命名您的模型。
您的用户模型最好继承回环的用户模型,因为您可能需要许多已实现的功能。
我创建了一个 api-server loopbackjs 应用程序,我想定义一个名为 User 的模型,它具有 与内置的完全不同的属性一个。所以当我 运行 slc loopback:model
时,它会抛出如下错误。
events.js:163
throw er; // Unhandled 'error' event
^
ValidationError: The `ModelDefinition` instance is not valid. Details: `name` is not unique (value: "User").
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:326:12
at ModelConstructor.<anonymous> (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:511:13)
at ModelConstructor.next (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/hooks.js:82:12)
at done (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:508:25)
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:586:7
at ModelConstructor.<anonymous> (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/validations.js:380:5)
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:1985:11
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:396:17
at done (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:167:19)
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:40:16
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:393:21
at /usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:1962:17
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
at doNotify (/usr/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/observer.js:99:49)
如果我真的需要在我的应用程序中调用一个名为 User 的模型,我真的很感激任何人都可以阐明这个问题。
loopback 带有一些内置模型;-) User 就是其中之一。 以小写字母(用户)命名您的模型。
您的用户模型最好继承回环的用户模型,因为您可能需要许多已实现的功能。