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

feat: Get references from manager #2982

Open
dickermoshe opened this issue May 2, 2024 · 4 comments
Open

feat: Get references from manager #2982

dickermoshe opened this issue May 2, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@dickermoshe
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
Make it easy to get referenced objects.

Describe the solution you'd like
This is the syntax that I've gotten to work.
I'm shocked that this is possible using Dart's very limited type system:

Syntax

await db.managers.todoItems.withReferences().withCategory().get()
// [(TodoItem(id: 31, title: Math, content: Do homework, category: 37), (category: Category(id: 37, description: School)))]

await db.managers.todoItems.withReferences().get()
//  [(TodoItem(id: 31, title: Math, content: Do homework, category: 37), (category: null))]

Type Hinting

The cool part is that when a with___ is not specified, the type hint is void:
image

And when added it's a nullable reference
image

I think this syntax is both developer friendly, while still being pretty simple in the source code.

@simolus3
What are your thoughts before I proceed?

@dickermoshe dickermoshe added the enhancement New feature or request label May 2, 2024
@simolus3
Copy link
Owner

simolus3 commented May 2, 2024

The API looks convincing, but I think I need some more details that aren't clear to me (but probably important to get right/clarified first):

  1. How (if at all) does this chain multiple reference links (e.g. if categories had outgoing references as well)? How do we deal with circular references (or self-references in a table)
  2. How does this play along with the rest of the manager API, in particular the methods to write filters? Will they still only use the primary table or is there a different state for joins as well?

@dickermoshe
Copy link
Collaborator Author

dickermoshe commented May 2, 2024

  1. I haven't experimented with how nesting would be done. It's isn't supported in my current implementation. Even so there wouldn't be any circular recursion issues.
  2. Once withReferences is called, it uses whatever filters and ordering were applied to the manager and wraps it in a new class. It will then run queries to get the referenced objects and attach them to a record. So filters and ordering can't be applied to what references get returned. Serverpod allows filtering what references are returned, but it's not type safe. I think it's worth it to have all-or-nothing and be type-safe

@dickermoshe
Copy link
Collaborator Author

dickermoshe commented May 2, 2024

I'll have a PR in a couple of minutes which will allow you to experiment with it.
Although modular will prob not work (temporarily)

@dickermoshe
Copy link
Collaborator Author

@simolus3 Check this out #2984

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

No branches or pull requests

2 participants