【发布时间】:2019-06-13 10:47:03
【问题描述】:
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
【问题讨论】:
标签: mysql node.js loopbackjs strongloop