Skip to content
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

LB4 todo-list example gives Error: Property "todoListId" cannot be changed! #2658

Closed
foobarrrz opened this issue Mar 28, 2019 · 6 comments · Fixed by #2754
Closed

LB4 todo-list example gives Error: Property "todoListId" cannot be changed! #2658

foobarrrz opened this issue Mar 28, 2019 · 6 comments · Fixed by #2754
Assignees

Comments

@foobarrrz
Copy link

foobarrrz commented Mar 28, 2019

I have cloned the project using cli "lb4 example todo-list" without modifying anything.

After I Inserted new record to "todo-list" model, I got the response.
{ "id": 3, "title": "newToDoList", "color": "red" }

then I use id = 3 as an input for POST /todo-lists/{id}/todos.

Unhandled error in POST /todo-lists/3/todos: 500 Error: Property "todoListId" cannot be changed!
    at Object.constrainDataObject (D:\Projects\NodeJs\lbex\loopback4-example-todo-list\node_modules\@loopback\repository\dist\repositor
ies\constraint-utils.js:49:19)
    at DefaultHasManyRepository.create (D:\Projects\NodeJs\lbex\loopback4-example-todo-list\node_modules\@loopback\repository\dist\rela
tions\has-many\has-many.repository.js:21:59)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I also try to create the relation model myself following the example.
https://loopback.io/doc/en/lb4/HasMany-relation.html
But it also give the same error.

@nabdelgadir
Copy link
Contributor

When you're trying to do a POST request for /todo-lists/{id}/todos, there's no need to supply the todoListId property since it's the one that replaces {id} in /todo-list/{id}/todos e.g. /todo-list/3/todos.

So I created your TodoList model: { "id": 3, "title": "newToDoList", "color": "red" }. Then I did a POST request - POST /todo-lists/3/todos with the following body:

{
  "id": 0,
  "title": "sample todo",
  "desc": "sample description",
  "isComplete": false
}

To which I received the following response body (and a 200 status code):

{
  "id": 5,
  "title": "sample todo",
  "desc": "sample description",
  "isComplete": false,
  "todoListId": 3
}

I believe when you add the todoListId property to your POST body, it passes this check, which is where the error comes from.

I'm thinking we can add this information to the documentation, specifically the HasMany relation page, what do you think?

@nabdelgadir nabdelgadir self-assigned this Apr 2, 2019
@nabdelgadir
Copy link
Contributor

Acceptance Criteria

  • Add a section to the HasMany relation docs explaining the format of the request body when doing a POST request (need to exclude the id of the "parent" [Category in the current docs] entity)

@emonddr
Copy link
Contributor

emonddr commented Apr 11, 2019

@b-admike will look to see if there is an existing bug related to the this check url mentioned above.

@bajtos
Copy link
Member

bajtos commented Apr 12, 2019

Most people don't read docs. Can we instead fix the constraint check to recognize the situation where the requested data is not changing the immutable key and don't report a false error?

@nabdelgadir
Copy link
Contributor

@b-admike if you can find the issue that's related to that check, we can close this issue. Otherwise, we can modify this issue to fix the constraint instead of the docs (or close this one and open a new issue).

@bajtos
Copy link
Member

bajtos commented Apr 12, 2019

I think the problem is has been described here first: #1719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants