mirror of https://gitee.com/bigwinds/arangodb
Foxx: Documentation of the new Model capabilities
This commit is contained in:
parent
5eed92d7a5
commit
6add03669b
|
@ -290,6 +290,39 @@ your model file, export the model as `model`.
|
|||
|
||||
A Foxx Model can be initialized with an object of attributes and their values.
|
||||
|
||||
There's also the possibility of annotation: The second hash you give to the
|
||||
extend method are properties of the prototype. You can define an attributes
|
||||
property there:
|
||||
|
||||
var Foxx = require("org/arangodb/foxx");
|
||||
|
||||
var PersonModel = Foxx.Model.extend({
|
||||
// Your instance properties
|
||||
}, {
|
||||
// Your prototype properties
|
||||
attributes: {
|
||||
name: { type: "string", required: true },
|
||||
age: { type: "integer" },
|
||||
active: { type: "boolean", defaultValue: true }
|
||||
});
|
||||
|
||||
exports.model = TodoModel;
|
||||
|
||||
This has two effects: On the one hand it provides documentation. If you annotated
|
||||
your model, you can use it in the `bodyParam` method for documentation.
|
||||
On the other hand it will influence the behavior of the constructor: If you provide
|
||||
an object to the constructor, it will only take those attributes that are listed
|
||||
in the attributes object. This is especially useful if you want to to initialize
|
||||
the Model from user input. On the other hand it will set the default value for all
|
||||
attributes that have not been set by hand. An example:
|
||||
|
||||
var person = new PersonModel({
|
||||
name: "Pete",
|
||||
admin: true
|
||||
});
|
||||
|
||||
person.attributes // => { name: "Pete", active: true }
|
||||
|
||||
### Extend
|
||||
|
||||
@copydetails JSF_foxx_model_extend
|
||||
|
|
|
@ -261,9 +261,11 @@ _.extend(Model.prototype, {
|
|||
/// @fn JSF_foxx_model_extend
|
||||
/// @brief Extend the Model prototype to add or overwrite methods.
|
||||
///
|
||||
/// @FUN{FoxxModel::extent(@FA{prototype})}
|
||||
/// @FUN{FoxxModel::extend(@FA{instanceProperties}, @FA{classProperties})}
|
||||
///
|
||||
/// Extend the Model prototype to add or overwrite methods.
|
||||
/// The first object contains the properties to be defined on the instance,
|
||||
/// the second object those to be defined on the prototype.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Model.extend = backbone_helpers.extend;
|
||||
|
|
Loading…
Reference in New Issue