Skip to content
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

Automatically create nested R object rules if required #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

philipstarkey
Copy link
Member

This Fixes daisylb#22

R rules that traverse many-to-one or many-to-many relationships are now broken up automatically within R.check() into multiple, chained R rules.

Tests to confirm both the original nested R syntax, and a the new unnested syntax, have been added.

This Fixes daisylb#22

`R` rules that traverse many-to-one or many-to-many relationships are now broken up automatically within `R.check()` into multiple, chained `R` rules.

Tests to confirm both the original nested R syntax, and a the new unnested syntax, have been added.
@philipstarkey
Copy link
Member Author

philipstarkey commented Jun 15, 2021

This almost certainly needs improvement given my increased familiarity with bridgekeeper.

I probably need to add some additional tests as I think there may be subtleties in manager attribute names vs query relations when traversing reverse many-to-many/one relationships (possibly when there are custom related_name attributes on the model field...something like that anyway)

for i, key_fragment in enumerate(fragments):
# Catch a many-to-many or many-to-one traversal and split it
# across multiple Rules
if not hasattr(lhs.__class__, "_meta"):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect there is a better way to detect this (like possibly even just if isinstance(lhs, Manager): as is used further down

@KyeRussell
Copy link
Member

I think there may be subtleties in manager attribute names vs query relations when traversing reverse many-to-many/one relationships (possibly when there are custom related_name attributes on the model field...something like that anyway)

Yep. I've run into lots of weird inconsistencies with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"R" raises an exception when following through a one-to-many relation
2 participants