loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

[LB-Next] Support of Relation for Repository and ModelDefinition

Open dhmlau opened this issue 9 years ago • 7 comments

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

dhmlau avatar Jun 30 '17 18:06 dhmlau

Cool...I will keep an eye on this thread

jonathan-casarrubias avatar Jun 30 '17 18:06 jonathan-casarrubias

@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?

kjdelisle avatar Jul 05 '17 20:07 kjdelisle

@raymondfeng bump

kjdelisle avatar Jul 11 '17 15:07 kjdelisle

cc @bajtos

kjdelisle avatar Jul 11 '17 15:07 kjdelisle

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

jonathan-casarrubias avatar Jul 11 '17 15:07 jonathan-casarrubias

I've created a new issue #812 and just realised it's duplicated.

ashdns avatar Jan 19 '18 14:01 ashdns

Closing this in favor of https://github.com/strongloop/loopback-next/issues/995

dhmlau avatar Feb 26 '18 17:02 dhmlau