website icon indicating copy to clipboard operation
website copied to clipboard

misleading documentation on "type" parameter

Open runfaj opened this issue 6 years ago • 2 comments

https://github.com/sequelize/sequelize/blob/ff1c97cd9264d50c1d779b31a8d38dd4182ddfaa/lib/sequelize.js#L427

This documentation indicates that ANY time the "type" parameter is specified, the returned result is the row, without the counts. However, looking at the actual code:

https://github.com/sequelize/sequelize/blob/ff1c97cd9264d50c1d779b31a8d38dd4182ddfaa/lib/dialects/postgres/query.js#L261

This is NOT the case with insert/update/raw. This should either be adjusted in the documentation to mention excluded cases, or should be updated in the Query to return the expected result for these other cases. I vote the latter personally, as it provides more code flexibility in general - but I do understand that would be a breaking change, since people would have had to work around this issue by now.

It should also be noted, that this was working properly in sequelize v3. When I started migrating to v4, this issue presented itself. Here's the example query I had to modify as a result:

   return sequelize.query(sql, {
        type: models.Sequelize.QueryTypes.UPDATE,
        replacements: {
          jobId,
          status: metricStatuses.PROCESSING,
          workerMeta: JSON.stringify(workerMeta),
        },
        raw: true,
      })
      .then(_.first) ////////// this shouldn't be needed, docs say setting the type avoids this
      .then(_.first);

runfaj avatar Dec 12 '18 15:12 runfaj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

stale[bot] avatar Mar 13 '19 16:03 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

stale[bot] avatar Jul 23 '19 22:07 stale[bot]