Closed igorbenav closed 1 week ago
@Justinianus2001 could you please provide sample models and schemas so I can reproduce?
Below are my schemas:
class ProjectReadSub(BaseModel):
id: int
project_code: str
status: ProjectStatus
name: str
start_date: datetime
end_date: datetime
class ProjectRead(ProjectReadSub):
department: DepartmentRead | None
assignee: UserReadSub | None
client: ClientRead | None
class DepartmentRead(BaseModel):
id: int
name: str
class UserReadSub(BaseModel):
id: int
name: str
username: str
email: EmailStr
phone: str | None
profile_image_url: str
department_id: int | None
company_id: int | None
class ClientRead(BaseModel):
id: int
name: str
contact: str
phone: str
email: str
The fields in the models correspond to those listed.
I expect the output to be as follows:
{
'id': 1,
'project_code': 'ABC1',
'status': 'Approved',
'name': 'Project Example',
'start_date': datetime.datetime(2024, 6, 5, 9, 26, 48, 914000, tzinfo=datetime.timezone.utc),
'end_date': datetime.datetime(2024, 6, 5, 9, 26, 48, 914000, tzinfo=datetime.timezone.utc),
'client': None,
'department': None,
'assignee': None
}
Hello, has the issue been resolved? I am still waiting for the solution and am currently avoiding this bug. Thank you!
I finished this yesterday, I'm just writing the tests and fixing some typing stuff
First mentioned in #101 by @Justinianus2001:
" I aim to retrieve a project and its nested objects based on client_id, department_id, and assignee_id as follows:
However, I encounter an issue: when a foreign key is null, the object is still returned but with all fields set to None.
How can I modify the query so that if a nested object's foreign key is null, the entire nested object is returned as None (e.g., 'client': None)? "