-
Notifications
You must be signed in to change notification settings - Fork 90
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
Reverse foreign key lookups #378
Comments
@dantownsend Is it necessary to have a ReverseLookup field specified by the user? class Band(Table):
name = Varchar()
manager = ForeignKey(Manager, reverse_lookup='bands')
|
@AliSayyah Good point - it could be done that way. The reverse lookup could then be created by the table metaclass. The only downside is it might not work as well with tab completion, but it's a simpler API for users. |
And what about generic reverve lookups for that? That way we have the best of both worlds, the automatic reverse lookup and the tab completion for the ones that use that |
One option is for the user to do something like this, which would give better tab completion: class Manager(Table):
name = Varchar()
bands: ReverseLookup
class Band(Table):
name = Varchar()
manager = ForeignKey(Manager, reverse_lookup='bands') |
@dantownsend We already have all the tools for reverse lookup without intervention in the source code. If we document properly, users will only have to write a few lines of code. My examples will be |
@sinisaos I looked at the gist - what you've done is similar to how I currently do it. I think having something built in would be nice. We'll get around to it eventually! You could put a page here if you like: https://piccolo-orm.readthedocs.io/en/latest/piccolo/tutorials/index.html |
@dantownsend Thank you for your reply. No need to add this to the docs because if anyone needs a workaround, they can find it here. I've updated the gist with your suggestion so it's all there. |
Now we have M2M, it makes sense to add something similar for reverse foreign key lookups.
This needs doing before v1.
Here's an example API design:
The text was updated successfully, but these errors were encountered: