How to pass a full object in an afterUpdate, beforeUpdate, afterCreate, beforeCreate, etc


#1

Documentation is a bit cryptic: “List of objs that were updated. The objs will already have been updated. By default, only the id is present in the obj unless a dependency include annotation specifies additional fields.” Concretely how do I specify the include spec?


#2

For beforeCreate, you will always get exactly what you passed in. For beforeUpdate/beforeRemove you will by default get the entire obj, read from the db, with your updates applied. For afterCreate/afterUpdate/afterRemove, by default you will get objs with only the id present. If you want fewer fields in beforeUpdate/beforeRemove (for better performance) or more fields in afterCreate/afterUpdate/afterRemove you can specify the @dependency annotation on the function as follows:

@dependency(include = “includeField1, includeField2…”)
afterCreate: ~

If you want every field it would be like:

@dependency(include = “this”)
afterCreate: ~

For afterCreate, since the obj is already removed, it will contain the obj with the requested fields as it was prior to being removed. For the other after… functions, it will contain those fields after the create/update operation.

I’ll update the documentation to make that a little clearer.