Add more jsdocs
This commit is contained in:
parent
e2ab9ccc93
commit
177752e144
|
@ -631,17 +631,19 @@ BelongsTo.prototype.related = function (refresh, params) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hasAndBelongsToMany relation creates a direct many-to-many connection with another model, with no intervening model.
|
* A hasAndBelongsToMany relation creates a direct many-to-many connection with
|
||||||
* For example, if your application includes users and groups, with each group having many users and each user appearing
|
* another model, with no intervening model. For example, if your application
|
||||||
* in many groups, you could declare the models this way:
|
* includes users and groups, with each group having many users and each user
|
||||||
|
* appearing in many groups, you could declare the models this way:
|
||||||
* ```
|
* ```
|
||||||
* User.hasAndBelongsToMany('groups', {model: Group, foreignKey: 'groupId'});
|
* User.hasAndBelongsToMany('groups', {model: Group, foreignKey: 'groupId'});
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param {String|Object} modelTo Model object (or String name of model) to which you are creating the relationship.
|
* @param {String|Object} modelTo Model object (or String name of model) to
|
||||||
* the relation
|
* which you are creating the relationship.
|
||||||
* @options {Object} params Configuration parameters; see below.
|
* @options {Object} params Configuration parameters; see below.
|
||||||
* @property {String} as Name of the property in the referring model that corresponds to the foreign key field in the related model.
|
* @property {String} as Name of the property in the referring model that
|
||||||
|
* corresponds to the foreign key field in the related model.
|
||||||
* @property {String} foreignKey Property name of foreign key field.
|
* @property {String} foreignKey Property name of foreign key field.
|
||||||
* @property {Object} model Model object
|
* @property {Object} model Model object
|
||||||
*/
|
*/
|
||||||
|
@ -676,10 +678,19 @@ RelationDefinition.hasAndBelongsToMany = function hasAndBelongsToMany(modelFrom,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasOne
|
* A HasOne relation creates a one-to-one connection from modelFrom to modelTo.
|
||||||
* @param modelFrom
|
* This relation indicates that each instance of a model contains or possesses
|
||||||
* @param modelTo
|
* one instance of another model. For example, each supplier in your application
|
||||||
* @param params
|
* has only one account.
|
||||||
|
*
|
||||||
|
* @param {Function} modelFrom The declaring model class
|
||||||
|
* @param {String|Function} modelTo Model object (or String name of model) to
|
||||||
|
* which you are creating the relationship.
|
||||||
|
* @options {Object} params Configuration parameters; see below.
|
||||||
|
* @property {String} as Name of the property in the referring model that
|
||||||
|
* corresponds to the foreign key field in the related model.
|
||||||
|
* @property {String} foreignKey Property name of foreign key field.
|
||||||
|
* @property {Object} model Model object
|
||||||
*/
|
*/
|
||||||
RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
|
RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
|
||||||
params = params || {};
|
params = params || {};
|
||||||
|
@ -723,6 +734,13 @@ RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a target model instance
|
||||||
|
* @param {Object} targetModelData The target model data
|
||||||
|
* @callback {Function} [cb] Callback function
|
||||||
|
* @param {String|Object} err Error string or object
|
||||||
|
* @param {Object} The newly created target model instance
|
||||||
|
*/
|
||||||
HasOne.prototype.create = function(targetModelData, cb) {
|
HasOne.prototype.create = function(targetModelData, cb) {
|
||||||
var modelTo = this.definition.modelTo;
|
var modelTo = this.definition.modelTo;
|
||||||
var fk = this.definition.keyTo;
|
var fk = this.definition.keyTo;
|
||||||
|
@ -740,6 +758,11 @@ HasOne.prototype.create = function(targetModelData, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a target model instance
|
||||||
|
* @param {Object} targetModelData The target model data
|
||||||
|
* @returns {Object} The newly built target model instance
|
||||||
|
*/
|
||||||
HasOne.prototype.build = function(targetModelData) {
|
HasOne.prototype.build = function(targetModelData) {
|
||||||
var modelTo = this.definition.modelTo;
|
var modelTo = this.definition.modelTo;
|
||||||
var pk = this.definition.keyFrom;
|
var pk = this.definition.keyFrom;
|
||||||
|
@ -756,9 +779,9 @@ HasOne.prototype.build = function(targetModelData) {
|
||||||
* - order.customer(customer): Synchronous setter of the target model instance
|
* - order.customer(customer): Synchronous setter of the target model instance
|
||||||
* - order.customer(): Synchronous getter of the target model instance
|
* - order.customer(): Synchronous getter of the target model instance
|
||||||
*
|
*
|
||||||
* @param refresh
|
* @param {Boolean} refresh Reload from the data source
|
||||||
* @param params
|
* @param {Object|Function} params Query parameters
|
||||||
* @returns {*}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
HasOne.prototype.related = function (refresh, params) {
|
HasOne.prototype.related = function (refresh, params) {
|
||||||
var modelTo = this.definition.modelTo;
|
var modelTo = this.definition.modelTo;
|
||||||
|
|
|
@ -193,7 +193,6 @@ describe('relations', function () {
|
||||||
Supplier.hasOne(Account);
|
Supplier.hasOne(Account);
|
||||||
Object.keys((new Account()).toObject()).should.include('supplierId');
|
Object.keys((new Account()).toObject()).should.include('supplierId');
|
||||||
(new Supplier()).account.should.be.an.instanceOf(Function);
|
(new Supplier()).account.should.be.an.instanceOf(Function);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be used to query data', function (done) {
|
it('can be used to query data', function (done) {
|
||||||
|
|
Loading…
Reference in New Issue