- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
As per this discussion其他资源可用于 v3 及更早版本,但我无法找到直接使用 loopback 4 添加外键的方法,这样当我从模型迁移数据库时,我仍然具有外键约束.
这是我到目前为止所拥有的,但迁移完成后我无法获得外键。
我的模型:
export class TodoList extends Entity {
@hasMany(() => Todo, { keyTo: 'todoListId' })
todos?: Todo[];
@property({
type: 'string',
})
todoListId: number;
我的存储库:
export class TodoListRepository extends DefaultCrudRepository<
TodoList,
typeof TodoList.prototype.id
> {
public readonly todos: HasManyRepositoryFactory<
Todo,
typeof Todo.prototype.id
>;
constructor(
@inject('datasources.todo') dataSource: TodoDataSource,
@repository.getter(TodoRepository)
protected todoRepositoryGetter: Getter<TodoRepository>,
) {
super(TodoList, dataSource);
this.todos = this.createHasManyRepositoryFactoryFor(
'todos',
todoRepositoryGetter,
);
}
}
我使用 MySQL 作为数据源。但是当我运行 npm run migrate
时,不会创建外键。
我希望将 toDoListId
列作为 todo 模型的外键。 Here's the tutorial I'm following
最佳答案
看起来必须在模型设置中定义外键。我不确定 lb 2 和 3 是否属于这种情况,但我能够在 lb4 中实现此功能。
此外,我认为您必须在 Todo
模型上创建这个特定的键。
@model({
settings: {
"foreignKeys": {
"todoListId": {
"name": "todoListId",
"foreignKey": "todoListId",
"entityKey": "id",
"entity": "TodoList"
}
}
}
})
export class Todo extends Entity { ...
https://loopback.io/doc/en/lb3/MySQL-connector.html#auto-migrateauto-update-models-with-foreign-keys
关于mysql - 如何在loopback4中添加外键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54266356/
我正在尝试将扩展的环回用户模型与 loopback-component-passport 一起用于 facebook 登录。登录本身是有效的,但我无法让它使用我的自定义用户模型而不是内置的“用户”。
用于文件(或文件)上传的 loopback-component-storage 文档是这样说的: loopback documentation 描述: Upload one or more files
在 lib/models/user-identity.js 中 function profileToUser(provider, profile, options) { // Let's c
我已在 iisnode Windows Web 应用程序上托管了我的环回 4 应用程序,该应用程序将端口作为管道提供,在我的环回 4 应用程序中,我将端口读取为 Process.env.PORT。我收
我使用环回来生成我的 api 和 AngularJS 来与之通信。我有一个模型叫 Sync包含以下记录: Sync": { "34": "{\"uuid\":\"287c6625-4a95-4e11-
我关注了Loopback4 datasources文档并放置 sample.datasource.json 和 sample.test.datasource.json 下的文件src/数据源 .每当我
如何在 Loopback 中定义 decimal(10,2)?我查看了 api 和示例,但无法正常工作。它只是不断地创建一个小数(10,0)。 columnName 确实会影响输出,但未设置精度和比例
我正在使用 Loopback,我想创建一个记录上传数量的上传接口(interface)。我将自己的模型与存储组件一起使用。 我正在使用存储组件的上传功能,并且我想在上传成功后更新对象属性“upload
场景是, 删除用户时,我们只是将名为“状态”的字段更新为 -1。 但是,在添加具有已删除电子邮件 ID 的用户时,内置的环回用户模型会抛出错误,因为电子邮件已存在,因为它仅检查电子邮件是否存在。我想检
我正在使用 Loopback 3 开发一个应用。我在 ServiceEvaluation 模型上创建了一个远程方法,以返回服务模型中的 ServiceEvaluations 和相关属性的列表。 Ser
我正在使用环回。在名为 Report 的模型中创建一个名为 stats 的新方法。我想在另一个名为 Acount 的模型中创建相同的方法,但参数是 id。 模型报告: Report.remoteMet
如何在环回中创建动态模型,而不是对所有模型使用命令“lb model”。 例如: 如果我想创建 30 个具有几乎相同属性的模型,那么会遇到一次又一次创建所有 30 个模型和那些相应属性的麻烦。 是否可
如何在环回中创建动态模型,而不是对所有模型使用命令“lb model”。 例如: 如果我想创建 30 个具有几乎相同属性的模型,那么会遇到一次又一次创建所有 30 个模型和那些相应属性的麻烦。 是否可
我正在开发一个环回项目,我有一个名为 Depot 的模型,它有一个字段 likersList,该字段是一个字符串数组(用户 id)我想找到其 likersList 中没有特定 userId 的所有 D
我很难理解 Loopback 4 中 Repositories 的概念,文档说: A Repository represents a specialized Service interface tha
所以我有下表: external_user_has_survey_question_answer 此表与表有 belongsTo 关系: external_user 现在我正在尝试查询 member_
我将 Loopback 3 与 Mysql 结合使用。我们使用动态数据模型。例如,包含“管理员”或“用户”等类型的 UserAnswers。我想为类型的 countOfAnswers 字段添加答案计数
我有一个环回应用程序,我希望能够在 API 调用中包含来自关系的计算属性。例如,假设我有一个 apartment 模型和一个 address 模型。 address 具有属性 city 和 state
对于某些端点,我在调用时返回一个函数而不是实际值(最后的代码)。看起来它只出现在我的 Patient 模型中的嵌套端点上。 例如localhost:3000/api/Patients/{id}/Mea
我是环回平台的新手。我按照这个教程loop-back official tutorial for third-party和本教程 also a tutorial that i find 。我想要做的是
我是一名优秀的程序员,十分优秀!