dchester / epilogue

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

Nesting associated data in JSON #193

Closed asmodehn closed 7 years ago

asmodehn commented 7 years ago

The goal here is to be enable a user to create, read, edit, delete associated data via nested JSON object...

mgudesblatart commented 7 years ago

Great work! I decided to go back to basics(handle MySQL querying myself) for the current rendition of my project, but I look forward to implementing epilogue with your changes in the future.

baptistemanson commented 7 years ago

Cool feature! If you want some inspirations for the edit part: https://github.com/baptistemanson/epilogue-association-write/blob/master/index.js

danvk commented 7 years ago

@asmodehn Just wanted to clarify -- this change lets you read "thick" data for one-to-many relationships, but won't let you create one-to-many relationships via a REST API?

asmodehn commented 7 years ago

@danvk reading "thick" data was already possible. But the creation had to be done in 2 steps. With this change, a user can create thick data in one call, passing the full json for the multiple associated resources. I just leveraged the include option for create() as already available in sequelize.

danvk commented 7 years ago

@asmodehn thanks -- turned out I forget to put associations: true in my epilogue.resource call. Doh!

nkagarw commented 7 years ago

@asmodehn Thanks a lot for adding this feature to POST nested JSON objects. Is there a plan to support PUT requests as well ? Please suggest a way to do updates with associations.

asmodehn commented 7 years ago

@nkagarw I haven't worked on this for a while so I dont remember much about it, sorry... I just remember trying to implement the put in a similar way, but things got a bit trickier so I gave up as I didnt need it at the time. Might be possible though...