dchester / epilogue

Create flexible REST endpoints and controllers from Sequelize models in your Express app
846 stars 116 forks source link

[Read Endpoint] Get data from two models #230

Open abhishekchotaliya opened 6 years ago

abhishekchotaliya commented 6 years ago

Using association, I can request /book/2/chapters, which will give me chapters data of book 2(But no book data).

But is there any 'hack' by which I can get book data + chapters data from the same url? something like this?

{
    "book": {
        ... all book 2 data ... ,
        "chapters": {
            ... all book 2 chapters data ....
        }
    }
}

If not, then is it possible to get a similar result with the use of middleware?

kevboutin commented 5 years ago

You are better off using a hasMany relationship and asking for book 2 for example. An example can be found here: https://github.com/dchester/epilogue/issues/235.