Replies: 9 comments
-
This is desired behaviour, discussed in #3439. |
Beta Was this translation helpful? Give feedback.
-
This is an intended feature to prevent errors such as invalid foreign keys from being keyed into the database. AFAIK, updating navigational properties requires sending another HTTP request directly to the controller that you'd like to modify the navigational property of. Hence,
See: |
Beta Was this translation helpful? Give feedback.
-
@dexdinesh this is because your not using the buildin default property format for your FK in export class UserDevice extends Entity {
// ...
@belongsTo(() => Users)
user_id: string; // <-- expected to be userId
} otherwise you have to configure your relation export class UserDevice extends Entity {
// ...
@belongsTo(() => Users, {keyTo: 'id', keyFrom: 'user_id'})
user_id: string;
} But I can't get this working either. |
Beta Was this translation helpful? Give feedback.
-
when I think I'm solving stuffs, I'm getting this error "statusCode":500,
"name":"TypeError",
"message":"Cannot read property 'type' of undefined","stack":"TypeError: Cannot read property 'type' of undefined\n at Object.resolveHasManyMetadata (/home/ludohen/github/ta-api-core-2/node_modules/@loopback/repository/dist/relations/has-many/has-many.helpers.js:22:22) [...] EDIT: found the reason for that, when it's not following the naming convention (using the id), all options have to be set (keyTo, KeyFrom and name) |
Beta Was this translation helpful? Give feedback.
-
@achrinza, what is the recommendation if I need a atomic transaciton? How is the community handling this use case? |
Beta Was this translation helpful? Give feedback.
-
@fabianorodrigo Common LoopBack 4 SQL connectors support database-level transaction isolation. Unfortunately I don’t have a concrete example to share right now. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Sorry @achrinza, but when you suggest two requests as a workaround to the problem "Navigational properties are not allowed in model", one to the parent model and another to the child, this requests are made by the client side, right? The transactions supported by connectors are just applicable if I received a request with all the data (parent and child) and then open transaction, insert in the parent, insert in the child and commit transaction. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late reply; this issue slipped through my radar. The atomicity can be handled at the server side by making 2 repository calls within a single request. This does mean a bit of extra logic in the controller, but this ensures atomicity. The issue of implementing navigational properties is that LoopBack 4 does not have first-class support for database-level foreign key constraints. This enables cross-database relations, though requires LoopBack 4 to re-implement certain database logic. Some connectors such as PostgreSQL support foreign key definitions in |
Beta Was this translation helpful? Give feedback.
-
Just for clarity, since I'm finding somewhat differing information in the docs, does this essentially mean that the MongoDB connector does not support n-1/1-n relationships between collections? |
Beta Was this translation helpful? Give feedback.
-
As I had already used relations in loop back4 project now when I tried to perform any crud operation it returns
500 Error: Navigational properties are not allowed in model data (model "UserDevice" property "user_id")
My models are as follows:
User Model:
User Device Model:
Error I always receive on Create and Update operation:
Beta Was this translation helpful? Give feedback.
All reactions