Skip to content

TodoList tutorial - GET ​/todos​/{id}​/todo-list gives unexpected response #4147

@emonddr

Description

@emonddr

TodoList tutorial - GET ​/todos​/{id}​/todo-list gives unexpected response
for a todo item that is not part of a todo list.

Current Behavior

In the Todo tutorial, a few todo items are already inside db.json.

[
  {
    "id": 1,
    "title": "Take over the galaxy",
    "desc": "MWAHAHAHAHAHAHAHAHAHAHAHAHAMWAHAHAHAHAHAHAHAHAHAHAHAHA"
  },
  {
    "id": 2,
    "title": "destroy alderaan",
    "desc": "Make sure there are no survivors left!"
  },
  {
    "id": 3,
    "title": "play space invaders",
    "desc": "Become the very best!"
  },
  {
    "id": 4,
    "title": "crush rebel scum",
    "desc": "Every.Last.One."
  },
]

They are not associated with any list.
No problem.

I reach the end of the TodoList tutorial
I create a TodoList #1
I add two new todo items to it.
No problem.

[
  {
    "id": 1,
    "title": "Take over the galaxy",
    "desc": "MWAHAHAHAHAHAHAHAHAHAHAHAHAMWAHAHAHAHAHAHAHAHAHAHAHAHA"
  },
  {
    "id": 2,
    "title": "destroy alderaan",
    "desc": "Make sure there are no survivors left!"
  },
  {
    "id": 3,
    "title": "play space invaders",
    "desc": "Become the very best!"
  },
  {
    "id": 4,
    "title": "crush rebel scum",
    "desc": "Every.Last.One."
  },
  {
    "id": 5,
    "title": "carrots",
    "desc": "White Carrots for soup",
    "isComplete": false,
    "todoListId": 1
  },
  {
    "id": 6,
    "title": "bananas",
    "desc": "Yellow bananas for banana bread",
    "isComplete": false,
    "todoListId": 1
  },
]

When I use
GET /todos​/{todo id}/todo-list for the two new todo items (id=5 or 6) above, I get the
proper response of

{
  "id": 1,
  "title": "grocery",
  "color": "green"
}

No problem.

But when I use
GET /todos​/{todo id}/todo-list for the any item items (id=1 through 4) above (not associated with a list), I get the unexpected response of:

{
  "id": 1,
  "title": "grocery",
  "color": "green"
}

todo with id=1 is not part of todoList id=1.

Expected Behavior

Expected a response of [ ].

Link to reproduction sandbox

Related Issues

See Reporting Issues for more tips on writing good issues

Acceptance Criteria

  • Find the underlying resolver's problem which returns orphan related item.
  • Fix the bug ^.

Metadata

Metadata

Assignees

Labels

ExamplesRelationsModel relations (has many, etc.)RepositoryIssues related to @loopback/repository packagebug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions