Replies: 2 comments 3 replies
-
Why not just do "count/scalar" on DB when needed instead of creating seperate col for it? |
Beta Was this translation helpful? Give feedback.
3 replies
-
I would also recommend not solving this in the database, but with Pydantic by upgrading to the latest SQLModel that supports Pydantic V2. You would then be able to define a model that is transforming your database Below an example for a computed field if the from pydantic import computed_field
class ParentRead(ParentBase):
@computed_field
@property
def children_counter(self) -> int:
return len(self.children) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I want to read the parent with the number of related children, but I don't want to read the child content.
Is there any way to define a field in SQLModel for counting the amount of relationships?
For example, something like that
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions