-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Many to many relation (hasAndBelongsToMany) #2043
Comments
Currently it is apparently not supported (only 1-to-many [hasMany] and the reciprocal relation [belongsTo] (see https://loopback.io/doc/en/lb4/Relations.html) but I have a similar need and I'd like to know (@raymondfeng) either for when it is planned on the roadmap and/or if it is possible to contribute to speed things up (and, if so, how to contribute). |
+1 |
Thanks for the feedback! It seems like there are more users who are looking for the other model relation types than what we have so far. As you might've known already, support of |
Hi all, thanks for your interest in contributing to more relation types! Would like to see who has a particular interest or need for a certain relation type. Not sure what's the best way to do a poll here, I'm going to add one comment for each relation type below, and if you would like to contribute or need it for your project, please upvote. Thanks! Here are the outstanding relation types: |
|
|
|
|
|
|
cc @strongloop/loopback-next @strongloop/loopback-maintainers |
HasManyThrough first but interested in other ones too
Le mer. 21 nov. 2018 à 15:51, Diana Lau <[email protected]> a écrit :
… cc @strongloop/loopback-next
<https://github.com/orgs/strongloop/teams/loopback-next>
@strongloop/loopback-maintainers
<https://github.com/orgs/strongloop/teams/loopback-maintainers>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2043 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACqwzcLwquCODmr0Jyh0bDIsRG_u0JTxks5uxWhsgaJpZM4YmxSz>
.
|
HasManyThrough, HasAndBelongsToMany. |
How can I contribute to the manyToMany ??? I really need it. |
I am proposing to keep this issue focused on "many to many" relation, and discuss other relation types in [EPIC] More Relations (post-GA) #1450. From what I remember from LB3, "many to many" relation is called So I think the first step is to figure out how to implement a "hasManyThrough" relation. In my experience so far, adding a new relation type has always been a challenge. It took multiple iterations until we were able to find a good design and a robust implementation. I expect that hasManyThrough will be similar. In general, each relation type needs the following artifacts:
I think the steps 2-5 should be relatively straightforward because they will mostly copy the design we already have in place for "hasMany" relation. I am expecting the first step to be most challenging, as we need to find out how to implement data access operations leveraging a "through" table. Process wise, I am proposing to start with a spike on the first step. Start designing a Repository interface and implementation that will provide the following APIs:
Use integration tests to test the implementation. See relation.factory.integration.ts for inspiration, but please start a new file instead. Open a pull request as soon as you have the first method ("create"?) implemented, so that we can discuss the design & implementation early on, while there is little code written and changes are easy to make. |
Thanks @bajtos, I'll see what I can do. |
Hello @bajtos, |
I'll be mostly away from my computer until the end of the year, I'll take a look in January. Merry Christmas! 🎄 |
Merry Christmas! |
Hello @bajtos, |
Hi @bajtos, |
@dhmlau, @raymondfeng , @gczobel-f5, @bajtos
|
For |
I hope this is an appropriate place to post this question.... Is there a workaround for implementing many-to-many relationships in Loopback 4.? I think there must be since just about any significant database model will contain some number of many-to-many relationships. Without official support or a good workaround, I doubt that Loopback 4 would have been deemed ready to release otherwise. Thanks |
The HasManyThrough pull request is currently functional. There's still more work to do on it to make it more efficient with SQL, but it does work. The code for the pull request can be found at the following link. You can install it by running the following . . .
. . . or by adding the following to the dependencies section in your package.json "@loopback/repository": "https://github.com/codejamninja/loopback-next/releases/download/%40loopback%2Frepository-has-many-through-using-has-many/loopback-repository-has-many-through-using-has-many-1.2.1.tgz" |
You can see an example of how to set it up and use it in the fixtures test. |
For hasManyThrough, you have to explicitly define your own join (junction) table. It's very similar to the way it works in loopback 3. You can read more about it at the following link. https://loopback.io/doc/en/lb3/HasManyThrough-relations.html In the example I provided, the junction table is defined by the Also, notice the way Since this feature has not been accepted into |
Like existing relationships in Loopback 4, you will need to wire it together in the repository. For the hasManyThrough relationship, you use the |
@codejamninja great work! Thank! |
Yes, absolutely. Look at the example below. https://github.com/codejamninja/medical-practice-api Currently, the physician repository isn't complete, but to complete it, it would simply be implemented in an identical fashion to the patient repository. Feel free to submit a pull request to finish the patient repository. |
Hi @codejamninja , I'm using your example with relational databases and I notice that when I generate the database schema, the many-to-many relationship is not generated with foreignkey, there is some way in which this relationship is defined when migrating the schema ? |
Any dates on when will this be merged? |
@dakt I have to go through the comments and make some changes before the team can merge it. I will hopefully get around to it sometime this month. I have a feeling there will probably be around 3 pull requests before |
is loopback 4 not ready for production use? it still seems to be missing this |
@AzeemMichael if your application needs a many to many relationship, then yes it's probably not production ready. However I have built several loopback 4 apps that are in production that do not use the many to many relationship. |
I find loopback 4 is one the greatest frameworks, however the many to many relation (HasManyThrough) is very essential to most of the work i intend to use loopback for, hope this be released soon. |
Hello guys ! Do you know when this feature is going to be available in the framework ? thanks in advance. |
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 |
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 |
hello !! |
Description / Steps to reproduce / Feature proposal
I want to implement many to many relation in loopback4 but I couldn't see the article or any documentation regarding many to many relation
The text was updated successfully, but these errors were encountered: