Define models relations in JSON file or in JavaScript code
e.g. LoopBack 3 has models relations definition in JSON file or in JavaScript code We would like to define models relations in LoopBack 4 as well. Definition of relations need to auto generate the api services.
@yagobski , do you think this spike cover what you're looking for? https://github.com/strongloop/loopback-next/issues/995 . If yes, is it ok to close this issue and continue the discussion over there? thanks.
I feel it's too earlier for team to discuss the declarative relation file before story https://github.com/strongloop/loopback-next/issues/1372 finished, we can revisit it later this month to groom it.
I think this feature proposal would be covered by https://github.com/strongloop/loopback-next/issues/1359
We'd like to move to LB4, but can't move until we are able to have relationships specified in a JSON model. Any idea on what milestone this issue will be a part of? Thanks!
@elv1s what kind of relations are you looking for? We already support hasMany and belongsTo as of 4.0 GA, the work on hasOne is in progress - see https://github.com/strongloop/loopback-next/pull/1879. The Epic https://github.com/strongloop/loopback-next/issues/1450 is keeping track of the remaining relations, could you please leave a comment there to mention the relations that are important to your project?
@elv1s maybe I misunderstood you. Are you saying that you would like everything relation-related to be provided by LB4 runtime based on few lines of JSON config? I mean the controller for REST API, repositories for accessing relation data, etc.?
@bajtos, yes your second comment is what I was interested in. Right now in LB3 we are driving the creation of the API with JSON models. Will we be able to use LB3 JSON models with relationships in LB4? The relationships hasMany, belongsTo and hasOne should cover our requirements.
Cross-posting https://github.com/strongloop/loopback-next/pull/1194#issuecomment-433419070.
Can lb3 model relations be used in lb4 with https://github.com/strongloop/loopback-datasource-juggler?
Yes, I think that should work if you create the models using juggler's DataSource and/or ModelBuilder APIs and thus completely bypass @loopback/repository. You will loose the ability to describe models as the OpenAPI schema though, you will need to implement a helper to build OpenAPI schema for juggler models yourself. Possible leveraging loopback-swagger.
@elv1s
Right now in LB3 we are driving the creation of the API with JSON models. Will we be able to use LB3 JSON models with relationships in LB4?
Hmm. I think our design should be flexible enough to allow you to do that, but I don't think we are going to support this use case out of the box, at least not in the next few months.
I have left a comment elsewhere explaining how to automatically wire repositories and controllers for models, the approach may work for you too. See https://github.com/strongloop/loopback-next/issues/1889#issuecomment-433384870
I think this discussion is somewhat related to Declarative Support #565
LB4 is great but changing model declaration will be hard to migrate from LB3 to LB4 without rewriting the whole application. Do you have any migration plan to follow from LB3 to LB4.
@yagobski
LB4 is great but changing model declaration will be hard to migrate from LB3 to LB4 without rewriting the whole application. Do you have any migration plan to follow from LB3 to LB4.
We are fully aware of this concern. We are discussing migration paths from LB 3.x in the issue https://github.com/strongloop/loopback-next/issues/1849 - feel free to join the discussion and/or upvote the issue.
{
"_id": ObjectId("5c8772e972fe042a505f663e"),
"taxonomyTypeId": ObjectId("5b7ba50c5ee376051498b78a"),
"name": "Name",
"status": NumberInt(1),
"created": ISODate("2019-03-12T08:50:49.257Z"),
"modified": ISODate("2019-03-12T08:50:49.257Z"),
"parentId": null
}
How to create this ObjectId via loopback. I am using LB4. I am new for this
@shashijangir sorry, your question is off-topic here. Please post it on StackOverflow, it's a place where are more people that can help you to get your question answered. Use the tag loopbackjs to make your question easier to find.
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.