Relation not mapping to object consistently #4816
Replies: 3 comments 5 replies
-
Can you provide a complete reproduction? Entity definition is not a reproduction on its own. Also you say you use qb.execute? As with that, there is no mapping to entities, so it cannot be a serialization problem on its own. In fact, using that method wont even group the results the way you say. |
Beta Was this translation helpful? Give feedback.
-
Apologies. I have created a simple repo here showing what I mean: https://github.com/zortoflaven/MikroORM If you look at the output, you will see that only the first "userRole" is a real object. [
{
"id":"445bff08-0258-45c4-98b8-a1b1b3997de5",
"Email":"test@test.com",
"workspaceRoles":[
{
"user":"445bff08-0258-45c4-98b8-a1b1b3997de5",
"workspace":{
"id":"8724b13e-9472-462f-b4be-927dc06f11fe",
"orgName":"Test"
},
"userRole":{
"UserRole":"Admin",
"Level":1
}
},
{
"user":"445bff08-0258-45c4-98b8-a1b1b3997de5",
"workspace":{
"id":"d278edec-97fc-4a7c-9999-df0b28967dba",
"orgName":"Test2"
},
"userRole":"Admin" //Why not an object?
}
]
},
{
"id":"445bff08-0258-45c4-98b8-a1b1b3997de5",
"Email":"test@test.com",
"workspaceRoles":[
{
"user":"445bff08-0258-45c4-98b8-a1b1b3997de5",
"workspace":{
"id":"8724b13e-9472-462f-b4be-927dc06f11fe",
"orgName":"Test"
},
"userRole":{
"UserRole":"Admin",
"Level":1
}
},
{
"user":"445bff08-0258-45c4-98b8-a1b1b3997de5",
"workspace":{
"id":"d278edec-97fc-4a7c-9999-df0b28967dba",
"orgName":"Test2"
},
"userRole":"Admin" //Why not an object?
}
]
}
] As mentioned, if you run this with an older version of MikroORM (< 5.8.4), the "userRole" property is a full object for all entries. |
Beta Was this translation helpful? Give feedback.
-
Updated to latest and everything looks to be working as expected. Many thanks for this. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Given the following entities and query, the "userRole" relation is not populating as expected.
Output
Expected behavior
The "userRole" property for each "workspaceRole" on User should be an object since we selected and joined the relation, however it seems that on some rows, it is not getting populated.
Additional context
This worked as expected prior to v5.8.4. I suspect it is related to the change made for #4741, though I am not certain.
Versions
Beta Was this translation helpful? Give feedback.
All reactions