Ghost/core/server/models
kirrg001 00cf043e15 Fixed missing defaults in model layer
no issue

- reported in the forum: https://forum.ghost.org/t/publishing-with-a-single-post-request-to-posts/1648
- the defaults are defined in two places
  1. on the schema level (defaults for the database)
  2. on the ORM (model layer)
- the defaults on the db layer are set correctly when inserting a new resource
- but if we don't apply all defaults on the model layer, it will happen that model events are emitted without the correct defaults
  - see comment in code base
  - it's caused by the fact that knex only returns the inserted resource id (probably caused by the fact knex has to support x databases)
- components/modules are listening on model events and expect:
  1. a complete set of attributes
  2. a complete set of defaults
  3. sanitized values e.g. bool, date
- this commit fixes:
  1. added missing defaults for user & post model
  2. sanitize booleans (0|1 => false|true)
  3. added tests to ensure this works as expected
  4. clarfies the usage of `defaults`

Regarding https://forum.ghost.org/t/publishing-with-a-single-post-request-to-posts/1648:
  - the post event was emitted with the following values {page: undefined, featured: undefined}
  - the urlservice receives this event and won't match the resource against collection filters correctly
  - NOTE: the post data in the db were correct
2018-06-26 16:35:23 +02:00
..
base Added debug log to Base model: emitChange 2018-06-26 15:26:49 +02:00
plugins 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00
relations 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00
accesstoken.js 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00
app-field.js Misc cleanup: moving files & naming functions 2015-06-15 09:43:19 +01:00
app-setting.js Misc cleanup: moving files & naming functions 2015-06-15 09:43:19 +01:00
app.js Switch to Eslint (#9197) 2017-11-01 13:44:54 +00:00
client-trusted-domain.js Add table columns for OAuth 2015-09-02 13:39:22 +01:00
client.js 🎨 😎 config env usages (#7929) 2017-02-03 18:25:39 +00:00
index.js Webhooks support for subscriber events (#9230) 2017-11-21 15:43:14 +00:00
invite.js Dynamic Routing: Added migration for routes.yaml file (#9692) 2018-06-22 20:28:01 +02:00
permission.js 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00
post.js Fixed missing defaults in model layer 2018-06-26 16:35:23 +02:00
refreshtoken.js Misc cleanup: moving files & naming functions 2015-06-15 09:43:19 +01:00
role.js Proper error handling for permissible implementations 2018-02-21 16:59:48 +01:00
settings.js 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00
subscriber.js 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00
tag.js Dynamic Routing Beta (#9596) 2018-06-05 19:02:20 +02:00
user.js Fixed missing defaults in model layer 2018-06-26 16:35:23 +02:00
webhook.js 🔥 Drop Node v4 Support 2018-05-01 14:06:18 +02:00