dchester / epilogue

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

sequelize findAndCountAll() issue with include #209

Open hehaka opened 7 years ago

hehaka commented 7 years ago

Hi, For the models which use associations through include there is an wrong count in the Content-Range header of the epilogue library.

According to https://github.com/sequelize/sequelize/issues/7225 You need to use distinct = true in the findAndCountAll options.

I have made a local workaround in the Controllers/list.js List.prototype.fetch = function(req, res, context) function by putting options.distinct = true;

You should populate it to the resource function options of the library.

hiradimir commented 6 years ago

I have same issue.


does epilogue is not maintained?

hiradimir commented 6 years ago

I found workaround with milestone.

<targetResource>.use({
      list: {
        fetch: {
          before: function (req, res, context) {
            context.options.col = '<col> ex: "TableName"."primaryKey" ';
            context.options.distinct = true;
            return context.continue;
          }
        }
      }
    })