Enable strictObjectIDCoercion for RoleMapping model#437
Conversation
Force the RoleMapping model to always store ids as ObjectId when using MongoDB connector. This is needed to allow users to query RoleMapping via "principalId" property.
062d395 to
bfb115f
Compare
|
@slnode test please |
|
Released in |
|
@bajtos : i just helped someone else for whom ACLs were not working because RoleMapping had principalId as string, not ObjectId. This bug is painful. Remind me please: why can't we just add this option to the built-in RoleMapping model in loopback core (or do the config in app.js at app boot if a feature flag is required) ? "options": {
"strictObjectIDCoercion": true
},I don't see anything in the PR that actually tests if the connector is mongo before applying this option to model-config.json so i assume it does not harm when using other connectors |
Backwards compatibility, as usually. See strongloop/loopback#3198 (comment)
You are welcome :)
I think that's what this pull request is effectively doing in new applications - setting the required feature flag the way how it can/should be set. Existing applications can apply the same approach - simply modify the {
"RoleMapping": {
"dataSource": "db",
"options": {
"strictObjectIDCoercion": true,
},
"public": false
}
}I do realise the current situation is unfortunate and I am happy to discuss other/better ways how to solve this problem. I think ideally we should fix the root cause, which IIRC lies in the way how foreign keys are treated by LoopBack - the type of foreign keys should be changed from @superkhau was already taking a stab at that issue, but with little success. You can search for "fix ObjectID coercion", here are few issues to get started:
|
Description
Force the RoleMapping model to always store ids as ObjectId when using MongoDB connector. This is needed to allow users to query RoleMapping via "principalId" property.
The solution uses a less-known feature where
server/model-config.jsoncan provide additional "options" to apply even to built-in models likeRoleMapping.Related issues
Checklist
guide