-
Notifications
You must be signed in to change notification settings - Fork 17
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
Using @reference for 1:n relationships #295
Comments
Hi @phillipcurl, The other thing you will loose by switching to a reference is the ability to add onDelete actions . |
Hi @phillipcurl, thank you for explaining this issue on detail on call. I think inverse references are a valuable addition to cruddl. I would propose this modelling syntax type House @rootEntity {
description: String
uuid: String @key
people: [Person] @reference(foreignKeyField: "houseUuid")
}
type Person @rootEntity {
name: String
houseUuid: String
house: House @reference(keyField: "houseUuid")
}
Not quite sure about the name
References are intended to be weak links, i.e. they don't add any restrictions between the two objects. I still want to keep this property in place. Therefore, there will be a few restrictions compared to relations:
Do you think the feature would work for you with these restrictions? |
Hi @Yogu! Thank you again for taking the time to chat and for the detailed response! I think I also think all of those restrictions make sense and align with what I was expecting. I think I just have a couple questions around the expected functionality:
Thank you again for your thoughts and work around this! Please let me know if there are any other details I can provide. |
Thanks for your input on the name. Not quite sure about it yet.
All filter options from You're using the term "robust" which leads me to another possible issue: indices. Currently, cruddl automatically creates indices on key fields. ArangoDB already has indices on
Yes, will add a meta field, just like with collect and relation fields. |
Sorry for the delay, and thank you for those details!
That's great news - thank you! Indices is a really interesting point. As I've been denormalizing/duplicating/flattening some data, I've found myself adding composite indices for commonly used filtering patterns on an ad hoc basis. I would be in support of automatically adding the indices on the inverse reference. I can totally see your point around coupling, but I think when adding the inverse reference, I'm intentionally introducing coupling. Would be very interested to hear how your use cases or thoughts might differ on that! |
Hi cruddl team! Thank you for all of your great work on this project. I apologize in advance for the length of this issue, but want to make sure I'm providing as much context as possible.
We currently have a scenario where we're leveraging the
@relation
directive for a number of 1:n relationships. This has given us a lot of flexibility in our API in terms of being able to fetch for entities in both directions of that relationship. What we're seeing as our collections have grown in size, though, is slow performance when those edges are leveraged, particularly when used in filtering.Example of current schema:
We really like that this allows us to do both of the following queries:
Where this had led to slow performance for larger collections, is that querying for
allPeople
that are associated with a particularHouse.id
generates the following AQL:The filtering in that query has been inefficient on large collections because of the graph traversal, regardless of how optimized the indices are. We know that we can solve this by leveraging
@reference
and bypassing the edge traversal when filtering in those scenarios. Updating the schema to:and running a query like:
generates the following AQL, which is much more efficient:
The downside to doing this is that you lose the queryability in both directions that leveraging
@relation
provides (e.g. querying for people in a house). So finally my question, is there a way in cruddl to leverage@reference
and generate the resolvers for resolving entities in the opposite direction of the reference - essentially a@reference
-based version of@relation(inverseOf: "")
? I know the modeling docs mention "In contrast to relations, it is however not possible to navigate from the referenced object to the referencing object", but I wanted to check with you all.If there's not a way to do this in cruddl, have there been any discussions on adding support for it? This can be done in pure AQL and would really help improve the performance when using cruddl for things that are a 1:n relationship. From the Arango docs:
Finally, is there anything else that's lost when switching a relationship from
@relation
to@reference
aside from being able to query in both directions?Please let me know if there's any other context I can provide, and thank you again for all of your great work on this project!
The text was updated successfully, but these errors were encountered: