bookshelf-advanced-serialization

(require("bookshelf-advanced-serialization"))(optionsopt)

Generates a configured plugin.

Parameters:
Name Type Attributes Description
options Object <optional>

An optional object optionally containing methods for customizing plugin behavior.

Properties
Name Type Attributes Default Description
getEvaluatorArguments function <optional>

A function which should return the array of arguments that will be applied to the contextDesignator function. Its this value is the model being serialized. See getDefaultEvaluatorArguments in the source code for the example of the default behavior.

handleEnsureRelation function <optional>

A function which will be called for each relation name in the ensureRelationsLoaded arrays. May return a promise. See defaultHandleEnsureRelation in the source code for the example of the default behavior, which, as you'd expect, simply loads the relation on the model if it is not already present. This option was driven by the Sequiturs use case, which special-cases relation names ending in 'CountPseudoRelation' in order to set on the model a 'Count' attribute whose value is the count of rows of the relation identified by the beginning of the relation name.

ensureRelationsVisibleAndInvisible boolean <optional>
false

A boolean which should be true only if you have also specified options.handleEnsureRelation. It specifies whether the plugin should, before serializing, load all relations listed in an ensureRelationsLoaded array--that is, whether it should call options.handleEnsureRelation for each relation listed in an ensureRelationsLoaded array--, regardless of whether the relations will be visible properties. Default plugin behavior corresponds to a value of false, which avoids the work of loading relations that will not be present in the serialization result. Note that even if this option is true, relations that are not visible properties will be removed from the model just before serializing--as is documented for this plugin's Model.toJSON.

defaultOmitNew boolean <optional>

A boolean which specifies a default value for the omitNew option to {model,collection}.toJSON(options). Specifying this option as true is a performant way to address this Bookshelf bug (https://github.com/tgriesser/bookshelf/issues/753)--though note that the plugin will address that bug even without this option or with a value of false, albeit in a less performant manner.

Source:
Returns:

A function that should be passed to bookshelf.plugin(), to register this plugin.

Classes

Model
Documentation generated by JSDoc 3.4.1 on Mon Apr 17 2017 23:01:37 GMT-0400 (EDT) using a modified version of the Minami theme.