Skip to content

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