Skip to content

Commit

Permalink
parse/format example
Browse files Browse the repository at this point in the history
in parse, when it doesn't response a tag column (e.g. only id is responsed), ||'[]' will add will set tags to empty, which in my opinion is not true. Similarly, in format, if tags is not provides, it should not be updated.
  • Loading branch information
eerenyuan committed Sep 19, 2018
1 parent 30ffc63 commit 2510355
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tutorials/parse-and-format.md
Expand Up @@ -9,11 +9,13 @@ methods:
Book = bookshelf.Model.extend({
tableName: 'books',
parse: function(response) {
response.tags = JSON.parse(response.tags || '[]');
if(response.tags)
response.tags = JSON.parse(response.tags);
return response;
},
format: function(attributes) {
attributes.tags = JSON.stringify(attributes.tags || []);
if(attributes.tags)
attributes.tags = JSON.stringify(attributes.tags);
return attributes;
}
});
Expand Down

0 comments on commit 2510355

Please sign in to comment.