First Check
Commit to Help
Example Code
def get_model_detail(session: Session, id: int):
data = session.query(ModelProfile, SubModelProfile).join(SubModelProfile, ModelProfile.id == SubModelProfile.mp_id).filter(ModelProfile.id == id).all()
return data
Description
- Above code is trying to retrieve one-to-many relationship of ModelProfile [1:M] SubModelProfile
- It results in duplicate ModelProfile in the result:
[
{
"ModelProfile": {
"model_version": "1",
"id": 1,
"created_at": "2021-09-15T14:01:52"
},
"SubModelProfile": {
"mp_id": 1,
"id": 1
}
},
{
"ModelProfile": {
"model_version": "1",
"id": 1,
"created_at": "2021-09-15T14:01:52"
},
"SubModelProfile": {
"mp_id": 1,
"id": 2
}
},
{
"ModelProfile": {
"model_version": "1",
"id": 1,
"created_at": "2021-09-15T14:01:52"
},
"SubModelProfile": {
"mp_id": 1,
"id": 3
}
}
]
Question: I'm expecting the result to look like:
[
{
"ModelProfile": {
"model_version": "1",
"id": 1,
"created_at": "2021-09-15T14:01:52"
},
"SubModelProfile": [
{
"mp_id": 1,
"id": 1
}, {
"mp_id": 1,
"id": 2
}, {
"mp_id": 1,
"id": 3
}
]
}
]
Or this (what I wish to achieve)
[
{
"model_profile": {
"model_version": "1",
"id": 1,
"created_at": "2021-09-15T14:01:52"
"sub_model_profiles": [
{
"mp_id": 1,
"id": 1
}, {
"mp_id": 1,
"id": 2
}, {
"mp_id": 1,
"id": 3
}
]
}
]
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.7.11
Additional Context
No response
First Check
Commit to Help
Example Code
Description
Question: I'm expecting the result to look like:
Or this (what I wish to achieve)
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.7.11
Additional Context
No response