Fix heading levels in docs/ markdown files.
This commit is contained in:
parent
8be4d095e2
commit
eabe29bb73
|
@ -14,9 +14,9 @@ var oracle = loopback.createDataSource({
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
### Methods
|
||||||
|
|
||||||
### dataSource.createModel(name, properties, options)
|
#### dataSource.createModel(name, properties, options)
|
||||||
|
|
||||||
Define a model and attach it to a `DataSource`.
|
Define a model and attach it to a `DataSource`.
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ var Customer = ds.createModel('Customer', {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### dataSource.discoverModelDefinitions([username], fn)
|
#### dataSource.discoverModelDefinitions([username], fn)
|
||||||
|
|
||||||
Discover a set of model definitions (table or collection names) based on tables or collections in a data source.
|
Discover a set of model definitions (table or collection names) based on tables or collections in a data source.
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ oracle.discoverModelDefinitions(function (err, models) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### dataSource.discoverSchema([owner], name, fn)
|
#### dataSource.discoverSchema([owner], name, fn)
|
||||||
|
|
||||||
Discover the schema of a specific table or collection.
|
Discover the schema of a specific table or collection.
|
||||||
|
|
||||||
|
@ -156,12 +156,12 @@ Discover the schema of a specific table or collection.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### dataSource.enableRemote(operation)
|
#### dataSource.enableRemote(operation)
|
||||||
|
|
||||||
Enable remote access to a data source operation. Each [connector](#connector) has its own set of set remotely enabled and disabled operations. You can always list these by calling `dataSource.operations()`.
|
Enable remote access to a data source operation. Each [connector](#connector) has its own set of set remotely enabled and disabled operations. You can always list these by calling `dataSource.operations()`.
|
||||||
|
|
||||||
|
|
||||||
### dataSource.disableRemote(operation)
|
#### dataSource.disableRemote(operation)
|
||||||
|
|
||||||
Disable remote access to a data source operation. Each [connector](#connector) has its own set of set enabled and disabled operations. You can always list these by calling `dataSource.operations()`.
|
Disable remote access to a data source operation. Each [connector](#connector) has its own set of set enabled and disabled operations. You can always list these by calling `dataSource.operations()`.
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ oracle.disableRemote('destroyAll');
|
||||||
- disabling the remoting for a method only affects client access (it will still be available from server models)
|
- disabling the remoting for a method only affects client access (it will still be available from server models)
|
||||||
- data sources must enable / disable operations before attaching or creating models
|
- data sources must enable / disable operations before attaching or creating models
|
||||||
|
|
||||||
### dataSource.operations()
|
#### dataSource.operations()
|
||||||
|
|
||||||
List the enabled and disabled operations.
|
List the enabled and disabled operations.
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ CoffeeShop.find({where: {location: {near: here}}, limit:3}, function(err, nearby
|
||||||
- `feet`
|
- `feet`
|
||||||
- `degrees`
|
- `degrees`
|
||||||
|
|
||||||
## Methods
|
### Methods
|
||||||
|
|
||||||
### geoPoint.distanceTo(geoPoint, options)
|
#### geoPoint.distanceTo(geoPoint, options)
|
||||||
|
|
||||||
Get the distance to another `GeoPoint`.
|
Get the distance to another `GeoPoint`.
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ var there = new GeoPoint({lat: 5, lng: 5});
|
||||||
console.log(here.distanceTo(there, {type: 'miles'})); // 438
|
console.log(here.distanceTo(there, {type: 'miles'})); // 438
|
||||||
```
|
```
|
||||||
|
|
||||||
### GeoPoint.distanceBetween(a, b, options)
|
#### GeoPoint.distanceBetween(a, b, options)
|
||||||
|
|
||||||
Get the distance between two points.
|
Get the distance between two points.
|
||||||
|
|
||||||
|
@ -60,12 +60,12 @@ Get the distance between two points.
|
||||||
GeoPoint.distanceBetween(here, there, {type: 'miles'}) // 438
|
GeoPoint.distanceBetween(here, there, {type: 'miles'}) // 438
|
||||||
```
|
```
|
||||||
|
|
||||||
## Properties
|
### Properties
|
||||||
|
|
||||||
### geoPoint.lat
|
#### geoPoint.lat
|
||||||
|
|
||||||
The latitude point in degrees. Range: -90 to 90.
|
The latitude point in degrees. Range: -90 to 90.
|
||||||
|
|
||||||
### geoPoint.lng
|
#### geoPoint.lng
|
||||||
|
|
||||||
The longitude point in degrees. Range: -180 to 180.
|
The longitude point in degrees. Range: -180 to 180.
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
You can expose a Model's instance and static methods to clients. A remote method must accept a callback with the conventional `fn(err, result, ...)` signature.
|
You can expose a Model's instance and static methods to clients. A remote method must accept a callback with the conventional `fn(err, result, ...)` signature.
|
||||||
|
|
||||||
### loopback.remoteMethod(fn, [options])
|
### Static Methods
|
||||||
|
|
||||||
|
#### loopback.remoteMethod(fn, [options])
|
||||||
|
|
||||||
Expose a remote method.
|
Expose a remote method.
|
||||||
|
|
||||||
|
@ -118,7 +120,7 @@ as follows (assuming `name` as the name of the input parameter to resolve):
|
||||||
then the value of `args['name']` is used if it is defined.
|
then the value of `args['name']` is used if it is defined.
|
||||||
2. Otherwise `req.param('name')` is returned.
|
2. Otherwise `req.param('name')` is returned.
|
||||||
|
|
||||||
## Remote hooks
|
### Remote hooks
|
||||||
|
|
||||||
Run a function before or after a remote method is called by a client.
|
Run a function before or after a remote method is called by a client.
|
||||||
|
|
||||||
|
@ -185,9 +187,9 @@ A `Model` representing the user calling the method remotely. **Note:** this is u
|
||||||
|
|
||||||
During `afterRemote` hooks, `ctx.result` will contain the data about to be sent to a client. Modify this object to transform data before it is sent.
|
During `afterRemote` hooks, `ctx.result` will contain the data about to be sent to a client. Modify this object to transform data before it is sent.
|
||||||
|
|
||||||
#### Rest
|
#### REST
|
||||||
|
|
||||||
When [loopback.rest](#loopbackrest) is used the following `ctx` properties are available.
|
When [loopback.rest](#loopbackrest) is used the following additional `ctx` properties are available.
|
||||||
|
|
||||||
##### ctx.req
|
##### ctx.req
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ var User = loopback.createModel('user', {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
### Methods
|
||||||
|
|
||||||
### Model.attachTo(dataSource)
|
#### Model.attachTo(dataSource)
|
||||||
|
|
||||||
Attach a model to a [DataSource](#data-source). Attaching a [DataSource](#data-source) updates the model with additional methods and behaviors.
|
Attach a model to a [DataSource](#data-source). Attaching a [DataSource](#data-source) updates the model with additional methods and behaviors.
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ User.attachTo(oracle);
|
||||||
|
|
||||||
**Note:** until a model is attached to a data source it will **not** have any **attached methods**.
|
**Note:** until a model is attached to a data source it will **not** have any **attached methods**.
|
||||||
|
|
||||||
## Properties
|
### Properties
|
||||||
|
|
||||||
### Model.properties
|
#### Model.properties
|
||||||
|
|
||||||
An object containing a normalized set of properties supplied to `loopback.createModel(name, properties)`.
|
An object containing a normalized set of properties supplied to `loopback.createModel(name, properties)`.
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ Outputs:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## CRUD and Query Mixins
|
### CRUD and Query Mixins
|
||||||
|
|
||||||
Mixins are added by attaching a vanilla model to a [data source](#data-source) with a [connector](#connectors). Each [connector](#connectors) enables its own set of operations that are mixed into a `Model` as methods. To see available methods for a data source call `dataSource.operations()`.
|
Mixins are added by attaching a vanilla model to a [data source](#data-source) with a [connector](#connectors). Each [connector](#connectors) enables its own set of operations that are mixed into a `Model` as methods. To see available methods for a data source call `dataSource.operations()`.
|
||||||
|
|
||||||
|
@ -146,11 +146,11 @@ Here is the definition of the `count()` operation.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Static Methods
|
### Static Methods
|
||||||
|
|
||||||
**Note:** These are the default mixin methods for a `Model` attached to a data source. See the specific connector for additional API documentation.
|
**Note:** These are the default mixin methods for a `Model` attached to a data source. See the specific connector for additional API documentation.
|
||||||
|
|
||||||
### Model.create(data, [callback])
|
#### Model.create(data, [callback])
|
||||||
|
|
||||||
Create an instance of Model with given data and save to the attached data source. Callback is optional.
|
Create an instance of Model with given data and save to the attached data source. Callback is optional.
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ User.create({first: 'Joe', last: 'Bob'}, function(err, user) {
|
||||||
|
|
||||||
**Note:** You must include a callback and use the created model provided in the callback if your code depends on your model being saved or having an `id`.
|
**Note:** You must include a callback and use the created model provided in the callback if your code depends on your model being saved or having an `id`.
|
||||||
|
|
||||||
### Model.count([query], callback)
|
#### Model.count([query], callback)
|
||||||
|
|
||||||
Query count of Model instances in data source. Optional query param allows to count filtered set of Model instances.
|
Query count of Model instances in data source. Optional query param allows to count filtered set of Model instances.
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ User.count({approved: true}, function(err, count) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.find(filter, callback)
|
#### Model.find(filter, callback)
|
||||||
|
|
||||||
Find all instances of Model, matched by query. Fields used for filter and sort should be declared with `{index: true}` in model definition.
|
Find all instances of Model, matched by query. Fields used for filter and sort should be declared with `{index: true}` in model definition.
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ User.find({
|
||||||
|
|
||||||
**Note:** See the specific connector's [docs](#connectors) for more info.
|
**Note:** See the specific connector's [docs](#connectors) for more info.
|
||||||
|
|
||||||
### Model.destroyAll([where], callback)
|
#### Model.destroyAll([where], callback)
|
||||||
|
|
||||||
Delete all Model instances from data source. **Note:** destroyAll method does not perform destroy hooks.
|
Delete all Model instances from data source. **Note:** destroyAll method does not perform destroy hooks.
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ Product.destroyAll({price: {gt: 99}}, function(err) {
|
||||||
|
|
||||||
> **NOTE:* `where` is optional and a where object... do NOT pass a filter object
|
> **NOTE:* `where` is optional and a where object... do NOT pass a filter object
|
||||||
|
|
||||||
### Model.findById(id, callback)
|
#### Model.findById(id, callback)
|
||||||
|
|
||||||
Find instance by id.
|
Find instance by id.
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ User.findById(23, function(err, user) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.findOne(where, callback)
|
#### Model.findOne(where, callback)
|
||||||
|
|
||||||
Find a single instance that matches the given where expression.
|
Find a single instance that matches the given where expression.
|
||||||
|
|
||||||
|
@ -262,11 +262,11 @@ User.findOne({id: 23}, function(err, user) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.upsert(data, callback)
|
#### Model.upsert(data, callback)
|
||||||
|
|
||||||
Update when record with id=data.id found, insert otherwise. **Note:** no setters, validations or hooks applied when using upsert.
|
Update when record with id=data.id found, insert otherwise. **Note:** no setters, validations or hooks applied when using upsert.
|
||||||
|
|
||||||
### Custom static methods
|
#### Custom static methods
|
||||||
|
|
||||||
Define a static model method.
|
Define a static model method.
|
||||||
|
|
||||||
|
@ -307,11 +307,11 @@ loopback.remoteMethod(
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Instance methods
|
### Instance methods
|
||||||
|
|
||||||
**Note:** These are the default mixin methods for a `Model` attached to a data source. See the specific connector for additional API documentation.
|
**Note:** These are the default mixin methods for a `Model` attached to a data source. See the specific connector for additional API documentation.
|
||||||
|
|
||||||
### model.save([options], [callback])
|
#### model.save([options], [callback])
|
||||||
|
|
||||||
Save an instance of a Model to the attached data source.
|
Save an instance of a Model to the attached data source.
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ joe.save(function(err, user) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### model.updateAttributes(data, [callback])
|
#### model.updateAttributes(data, [callback])
|
||||||
|
|
||||||
Save specified attributes to the attached data source.
|
Save specified attributes to the attached data source.
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ user.updateAttributes({
|
||||||
}, fn);
|
}, fn);
|
||||||
```
|
```
|
||||||
|
|
||||||
### model.destroy([callback])
|
#### model.destroy([callback])
|
||||||
|
|
||||||
Remove a model from the attached data source.
|
Remove a model from the attached data source.
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ model.destroy(function(err) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Custom instance methods
|
#### Custom instance methods
|
||||||
|
|
||||||
Define an instance method.
|
Define an instance method.
|
||||||
|
|
||||||
|
@ -363,9 +363,9 @@ Define a remote model instance method.
|
||||||
loopback.remoteMethod(User.prototype.logout)
|
loopback.remoteMethod(User.prototype.logout)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Relationships
|
### Relationships
|
||||||
|
|
||||||
### Model.hasMany(Model, options)
|
#### Model.hasMany(Model, options)
|
||||||
|
|
||||||
Define a "one to many" relationship.
|
Define a "one to many" relationship.
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ Book.create(function(err, book) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.belongsTo(Model, options)
|
#### Model.belongsTo(Model, options)
|
||||||
|
|
||||||
A `belongsTo` relation sets up a one-to-one connection with another model, such
|
A `belongsTo` relation sets up a one-to-one connection with another model, such
|
||||||
that each instance of the declaring model "belongs to" one instance of the other
|
that each instance of the declaring model "belongs to" one instance of the other
|
||||||
|
@ -428,7 +428,7 @@ in one of the following styles:
|
||||||
post.author(user) // Set the author to be the given user
|
post.author(user) // Set the author to be the given user
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.hasAndBelongsToMany(Model, options)
|
#### Model.hasAndBelongsToMany(Model, options)
|
||||||
|
|
||||||
A `hasAndBelongsToMany` relation creates a direct many-to-many connection with
|
A `hasAndBelongsToMany` relation creates a direct many-to-many connection with
|
||||||
another model, with no intervening model. For example, if your application
|
another model, with no intervening model. For example, if your application
|
||||||
|
@ -443,9 +443,9 @@ appearing in many groups, you could declare the models this way,
|
||||||
user.groups.remove(group, callback); // remove the user from the group
|
user.groups.remove(group, callback); // remove the user from the group
|
||||||
```
|
```
|
||||||
|
|
||||||
## Validations
|
### Validations
|
||||||
|
|
||||||
### Model.validatesFormatOf(property, options)
|
#### Model.validatesFormatOf(property, options)
|
||||||
|
|
||||||
Require a model to include a property that matches the given format.
|
Require a model to include a property that matches the given format.
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ Require a model to include a property that matches the given format.
|
||||||
User.validatesFormat('name', {with: /\w+/});
|
User.validatesFormat('name', {with: /\w+/});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.validatesPresenceOf(properties...)
|
#### Model.validatesPresenceOf(properties...)
|
||||||
|
|
||||||
Require a model to include a property to be considered valid.
|
Require a model to include a property to be considered valid.
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ Require a model to include a property to be considered valid.
|
||||||
User.validatesPresenceOf('first', 'last', 'age');
|
User.validatesPresenceOf('first', 'last', 'age');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.validatesLengthOf(property, options)
|
#### Model.validatesLengthOf(property, options)
|
||||||
|
|
||||||
Require a property length to be within a specified range.
|
Require a property length to be within a specified range.
|
||||||
|
|
||||||
|
@ -469,7 +469,7 @@ Require a property length to be within a specified range.
|
||||||
User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
|
User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.validatesInclusionOf(property, options)
|
#### Model.validatesInclusionOf(property, options)
|
||||||
|
|
||||||
Require a value for `property` to be in the specified array.
|
Require a value for `property` to be in the specified array.
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ Require a value for `property` to be in the specified array.
|
||||||
User.validatesInclusionOf('gender', {in: ['male', 'female']});
|
User.validatesInclusionOf('gender', {in: ['male', 'female']});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.validatesExclusionOf(property, options)
|
#### Model.validatesExclusionOf(property, options)
|
||||||
|
|
||||||
Require a value for `property` to not exist in the specified array.
|
Require a value for `property` to not exist in the specified array.
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ Require a value for `property` to not exist in the specified array.
|
||||||
User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
|
User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.validatesNumericalityOf(property, options)
|
#### Model.validatesNumericalityOf(property, options)
|
||||||
|
|
||||||
Require a value for `property` to be a specific type of `Number`.
|
Require a value for `property` to be a specific type of `Number`.
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ Require a value for `property` to be a specific type of `Number`.
|
||||||
User.validatesNumericalityOf('age', {int: true});
|
User.validatesNumericalityOf('age', {int: true});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Model.validatesUniquenessOf(property, options)
|
#### Model.validatesUniquenessOf(property, options)
|
||||||
|
|
||||||
Ensure the value for `property` is unique in the collection of models.
|
Ensure the value for `property` is unique in the collection of models.
|
||||||
|
|
||||||
|
@ -509,7 +509,7 @@ Currently supported in these connectors:
|
||||||
- [Oracle](http://github.com/strongloop/loopback-connector-oracle)
|
- [Oracle](http://github.com/strongloop/loopback-connector-oracle)
|
||||||
- [MongoDB](http://github.com/strongloop/loopback-connector-mongodb)
|
- [MongoDB](http://github.com/strongloop/loopback-connector-mongodb)
|
||||||
|
|
||||||
### myModel.isValid()
|
#### myModel.isValid()
|
||||||
|
|
||||||
Validate the model instance.
|
Validate the model instance.
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ user.isValid(function (valid) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### loopback.ValidationError
|
#### loopback.ValidationError
|
||||||
|
|
||||||
`ValidationError` is raised when the application attempts to save an invalid
|
`ValidationError` is raised when the application attempts to save an invalid
|
||||||
model instance.
|
model instance.
|
||||||
|
@ -582,6 +582,6 @@ MyModel.prototype.preflight = function(changes, callback) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Shared methods
|
### Shared methods
|
||||||
|
|
||||||
Any static or instance method can be decorated as `shared`. These methods are exposed over the provided transport (eg. [loopback.rest](#rest)).
|
Any static or instance method can be decorated as `shared`. These methods are exposed over the provided transport (eg. [loopback.rest](#rest)).
|
||||||
|
|
Loading…
Reference in New Issue