-
Notifications
You must be signed in to change notification settings - Fork 1.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigational properties are not allowed in model data #4354
Comments
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: |
@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. |
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) |
@achrinza, what is the recommendation if I need a atomic transaciton? How is the community handling this use case? |
@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! |
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. |
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 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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:
The text was updated successfully, but these errors were encountered: