diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8ba24..355588f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [2.0.1](https://github.com/seegno/bookshelf-json-columns/tree/2.0.1) (2016-11-11) +[Full Changelog](https://github.com/seegno/bookshelf-json-columns/compare/2.0.0...2.0.1) + +**Closed issues:** + +- model.refresh is not working properly | bug [\#42](https://github.com/seegno/bookshelf-json-columns/issues/42) +- Malformed array literal [\#41](https://github.com/seegno/bookshelf-json-columns/issues/41) + +**Merged pull requests:** + +- Add user to postgres knexfile [\#44](https://github.com/seegno/bookshelf-json-columns/pull/44) ([ricardogama](https://github.com/ricardogama)) +- Fix parsing on saving through query [\#43](https://github.com/seegno/bookshelf-json-columns/pull/43) ([ricardogama](https://github.com/ricardogama)) + ## [2.0.0](https://github.com/seegno/bookshelf-json-columns/tree/2.0.0) (2016-10-25) [Full Changelog](https://github.com/seegno/bookshelf-json-columns/compare/1.2.2...2.0.0) diff --git a/dist/index.js b/dist/index.js index 31704f8..186b456 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16,6 +16,9 @@ function stringify(model, attributes, options) { return; } + // Mark json columns as stringfied. + options.parseJsonColumns = true; + this.constructor.jsonColumns.forEach(column => { if (this.attributes[column]) { this.attributes[column] = JSON.stringify(this.attributes[column]); @@ -27,9 +30,17 @@ function stringify(model, attributes, options) { * Parse JSON columns. */ -function parse(model, response, options) { +function parse(model, response) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + // Do not parse with `patch` option. - if (options && options.patch) { + if (options.patch) { + return; + } + + // Do not parse on `fetched` event after saving. + // eslint-disable-next-line no-underscore-dangle + if (!options.parseJsonColumns && options.query && options.query._method !== 'select') { return; } diff --git a/package.json b/package.json index 5d8ca2d..9805c62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bookshelf-json-columns", - "version": "2.0.0", + "version": "2.0.1", "description": "Parse JSON columns with Bookshelf.js", "license": "MIT", "author": {