[LB-Next] Support of Relation for Repository and ModelDefinition
Description/Steps to reproduce
For example, Customer and Order has the belongsTo relation. When customerId was given, it becomes the filter for the Order repository. It implies that Order repository is not a free form repository but is constrained by customerID=xxx.
- When doing CRUD operation, make sure this constraint is honoured.
- Currently, we are using primary key/foreign key for the relationship. In LB Next, we should allow people to use any properties.
In LB3, we support the following types of model relation:
- [ ] BelongsTo
- [ ] HasOne
- [ ] HasMany
- [ ] HasManyThrough
- [ ] HasAndBelongsToMany
- [ ] Polymorphic
- [ ] EmbedsOne
- [ ] EmbedsMany
- [ ] ReferencesMany
Coming from discussion with @raymondfeng
related to #420
BLOCKED BY
- https://github.com/strongloop/loopback-next/issues/537
Cool...I will keep an eye on this thread
@raymondfeng I'm not certain how the relation decorators fit into the loopback-next story; if we want to allow developers to mount their own ORMs and frameworks for retrieving data, there's a good chance that they'll have their own way of defining schemas for those datasources.
Using https://www.npmjs.com/package/sequelize-typescript as an example:
import {Table, Column, Model, HasMany} from 'sequelize-typescript';
@Table
class Person extends Model<Person> {
@Column
name: string;
@Column
birthday: Date;
@HasMany(() => Hobby)
hobbies: Hobby[];
}
Sequelize (the TypeScript version in particular) is leveraging its own idea of what these relations mean. If we build this ourselves, will it only be meant for the legacy-juggler-bridge? If so, aren't users still expected to define their relations in JSON, rather than use annotations?
@raymondfeng bump
cc @bajtos
I would just like to add, we need a way to discover models and relationships, not sure if this will be part of the open-api spec, else we need to somehow discover these relationships in order to auto-generate SDKs and it is imperative to build platforms on top of LBN
I've created a new issue #812 and just realised it's duplicated.
Closing this in favor of https://github.com/strongloop/loopback-next/issues/995