Open 5v3n-08 opened 3 years ago
@imnotjames let's discuss loadRelationIds
feature:
loadRelationIds
is a weird feature to have. It's very old (came from 0.1.x era).users!: User[] | string[];
- not the best UX, and everywhere it used user needs to put type guard checks @RelationId
decorator, but it's abandoned, I don't even know if still properly workHowever I think sometimes it's useful feature, we just have ugly implementation. Right now I have 3 options in my mind:
@RelationId
state and make loadRelationIds
to accept @RelationId
-marked properties (and map to them):Department.find({
loadRelationIds: {
userIds: true,
photos: {
albumIds: true
}
}
})
(same as ["userIds", "photos.albumIds"])
DepartmentRepo.find({
select: {
users: {
id: true
}
}
})
The result will contain the full "department" (by @future
design all columns are selected until at least one column (not relation) isn't specified in the selection) + "users" property with only "id" inside.
I'm more thinking towards #2
because it doesn't bring any new functionality / complexity and does solve the problem of having only relation ids. Plus we don't need to add extra properties into the model.
Lose database relations when use loadRelationIds
Steps to Reproduce
UserEntity:
DepartmentEntity:
Controller:
Expected Behavior
When a model is loaded with loadRelationIds, all relations should be kept when saving without overwriting them.
Actual Behavior
If I save the user model as in the example, all department relations will be deleted.
My Environment
Additional Context
Should this behavior be correct, is there a workaround or a better way? I actually only work with relation ids.
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?