dchester / epilogue

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

Unexpected joins on item fetch #109

Closed mark-lester closed 8 years ago

mark-lester commented 8 years ago

I would expect /api/Stops/1 to return a single Stop record of id==1. But as Stops has a one to many relation on StopTimes then a join on any related tables is performed and I get a row for each matching StopTime. Is this expected behaviour?. I hacked out this line https://github.com/dchester/epilogue/blob/master/lib/Controllers/read.js#L42 to get what I want, i.e a single record, but do I need to just set a switch to stop this,

mbroadst commented 8 years ago

@mark-lester can you provide a small code sample (perhaps based off of this) illustrating your problem. It'll just be easier to get this fixed that way

mark-lester commented 8 years ago

@mbroadst yes I'll try and bump that test out and return.

mark-lester commented 8 years ago

I'm making up a 107 test, though I am now using /entity?foreignKey=parent_id as that gives me the nested parents which is handy. I'm only pushing parent relations, i.e. HasOne|BelongsTo and that gives me what I want.

mark-lester commented 8 years ago

I am up and running (test 109), but it's now doing what you'd expect, which is a nested array of sub members, so I think we should close this and if anything comes back, or I have any PRs, at least I can ship you a mocha file.

mbroadst commented 8 years ago

sounds good