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

🎨 Ignore ManyToOneRel in get_relational_fields #429

Merged
merged 2 commits into from
Sep 9, 2024
Merged

Conversation

falexwolf
Copy link
Member

@falexwolf falexwolf commented Sep 9, 2024

User is a foreign key on almost all entities. For any given user, I might find it convenient to query all artifacts that the user ingested via: user.artifact_set.all()

However, I have a hard time imagining a query that looks like so because the result is always going to be exactly one user; the user that’s directly available as artifact.created_by

ln.User.filter(artifact=artifact).all()

Sometimes, I might only have the uid of an artifact. In that case, I can either query the user table or the artifact table directly. Querying the user table will be slightly faster.

ln.User.get(artifact__uid=artifact_uid)

The clutter produced by accounting for these backward references is enormous. For instance, on User:
image

I conclude that the minimal benefits in convenience for writing queries of the form user.artifact_set.all() do not justify the clutter in the API.

This present PR is making a change that hides these backward relationships (ManyToOneRel).

A second PR will create a migration that prevents Django from dynamically generating these attributes.

Internal reference.

@falexwolf falexwolf changed the title 🎨 Ignore ManyToOneRel in get_relational_fields 🎨 Ignore ManyToOneRel in get_relational_fields Sep 9, 2024
@falexwolf falexwolf merged commit 9e341e0 into main Sep 9, 2024
1 check passed
@falexwolf falexwolf deleted the relations branch September 9, 2024 05:41
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.

1 participant