0

I have created 2 models Author and Books where Author has hasMany relation with Book and Book has belongsTo relation with author.

While saving data using ORM models the cascading is not happening i.e

{
    "authorId": 1,
    "name": "qwery",
    "experience": 2,
    "books": [{
        "BookId": 12,
        "category": "string"
    }]
}

The above should create a Author record in Author table and create a Book record with the authorId in Book table, which is not happening whereas from belongsTo it can able to create an Author record with just authorId.

You can find the code in the following GIT

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
sunilsmith
  • 111
  • 2
  • 15

1 Answers1

0

You need to create a AuthorBookController to connect the two. Please see example code in here: https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/controllers/todo-list-todo.controller.ts

Diana
  • 311
  • 1
  • 3