Problems with circular references #208
andresmanz
started this conversation in
Ideas
Replies: 1 comment
-
Hey, @andresmanz. Thank you for raising this! The Data library does not support inverse relationships in the sense that you expect them to work. I'd very much like to add the support for that though! Not sure what I think about the We can start by writing the logic that'd allow the library to infer inverse relationships based on model definitions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I stumbled across a circular reference problem with this db:
So in this example I create a user and a team and then add the user to the team as an admin.
In the test for a member list, two endpoints are called:
/users/me
returns the user with their memberships/teams/:id/memberships
returns a team's membershipsHowever, I noticed that MSW's response for
/users/me
was always null.JSON.stringify(updatedUser) throws the following error because the user and the membership reference each other:
This issue could be worked around, but it could get annoying quickly. So I'd like to provide some feedback, mostly based on ORM experience:
manyOf
Relation not Being Updated When Updating Relationship with MSW #92.related objects as copies instead of references.
Nr 2 would solve the circular reference problem. Nr 1 could potentially make testing a bit easier and more intuitive. I'd imagine something like the following code to work:
expected result:
Nr 3, as a bonus: Sometimes you need to access a related object's id without populating the related object. You can set the id explicitly along with the related object, but it would be nice to have msw data do this automatically. Example:
I'm sorry if this is stupid or doesn't align with the plans for msw data at all. Feel free to ignore in that case. Also, sorry for that huge wall of text :(
Beta Was this translation helpful? Give feedback.
All reactions