hapi-sequelize-crud icon indicating copy to clipboard operation
hapi-sequelize-crud copied to clipboard

Support nested includes

Open casalot opened this issue 8 years ago • 5 comments

I have the following associations defined:

module.exports = ({
  Assessment, Event, Organisation
}) => {
  Event.hasMany(Assessment, {foreignKey:'eventId'});
  Event.belongsTo(Organisation, {foreignKey:'organisationId'});
}

Calling http://localhost:3030/api/seq/events?include=Assessment or http://localhost:3030/api/seq/events?include=Organisation produces the response, including the associated entity. But http://localhost:3030/api/seq/events?include=[Assessment,Organisation] includes none of the associated entities.

casalot avatar Jul 13 '16 06:07 casalot

The standard way to represent arrays in HTTP GET parameters is include[]=Assessment&include[]=Organisation, may you try that?

mdibaiee avatar Jul 13 '16 06:07 mdibaiee

Perfect! That works, thanks.

One more question. If I had nested associations, e.g. Event hasMany Assessments hasMany Questions, how would the GET request parameters look?

casalot avatar Jul 13 '16 06:07 casalot

Great!

Um, nested associations are not supported at the moment. You can create a pull-request if you want.

mdibaiee avatar Jul 13 '16 06:07 mdibaiee

Uhm, I had a look at the code, and don't think I'll be able to get this done ... Will leave it as a feature request for you, whenever you get the time.

Thanks for sorting out the other issues so quickly!

casalot avatar Jul 13 '16 07:07 casalot

Alright, that's fine. Thank you for reporting and following up with the issues.

mdibaiee avatar Jul 13 '16 07:07 mdibaiee