add support for relationship options

Signed-off-by: Jaka Hudoklin <jakahudoklin@gmail.com>
This commit is contained in:
Jaka Hudoklin 2014-07-21 22:39:06 +02:00
parent 857deb1130
commit b1a1894635
2 changed files with 13 additions and 6 deletions

View File

@ -399,7 +399,8 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
var params = { var params = {
foreignKey: relation.foreignKey, foreignKey: relation.foreignKey,
as: name, as: name,
model: model model: model,
options: relation.options
}; };
if (throughModel) { if (throughModel) {
params.through = throughModel; params.through = throughModel;
@ -418,7 +419,8 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
foreignKey: relation.foreignKey, foreignKey: relation.foreignKey,
as: name, as: name,
model: targetModel, model: targetModel,
through: model through: model,
options: relation.options
}; };
modelClass[relation.type].call(modelClass, name, params); modelClass[relation.type].call(modelClass, name, params);
} }
@ -444,7 +446,8 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
var params = { var params = {
foreignKey: r.foreignKey, foreignKey: r.foreignKey,
as: rn, as: rn,
model: targetModel model: targetModel,
options: r.options
}; };
if (throughModel) { if (throughModel) {
params.through = throughModel; params.through = throughModel;

View File

@ -70,6 +70,7 @@ function RelationDefinition(definition) {
this.keyThrough = definition.keyThrough; this.keyThrough = definition.keyThrough;
this.multiple = (this.type !== 'belongsTo' && this.type !== 'hasOne'); this.multiple = (this.type !== 'belongsTo' && this.type !== 'hasOne');
this.properties = definition.properties || {}; this.properties = definition.properties || {};
this.options = definition.options || {};
this.scope = definition.scope; this.scope = definition.scope;
} }
@ -363,7 +364,8 @@ RelationDefinition.hasMany = function hasMany(modelFrom, modelTo, params) {
modelTo: modelTo, modelTo: modelTo,
multiple: true, multiple: true,
properties: params.properties, properties: params.properties,
scope: params.scope scope: params.scope,
options: params.options
}); });
if (params.through) { if (params.through) {
@ -872,7 +874,8 @@ RelationDefinition.belongsTo = function (modelFrom, modelTo, params) {
modelFrom: modelFrom, modelFrom: modelFrom,
keyFrom: fk, keyFrom: fk,
keyTo: idName, keyTo: idName,
modelTo: modelTo modelTo: modelTo,
options: params.options
}); });
modelFrom.dataSource.defineForeignKey(modelFrom.modelName, fk, modelTo.modelName); modelFrom.dataSource.defineForeignKey(modelFrom.modelName, fk, modelTo.modelName);
@ -1082,7 +1085,8 @@ RelationDefinition.hasOne = function (modelFrom, modelTo, params) {
keyFrom: pk, keyFrom: pk,
keyTo: fk, keyTo: fk,
modelTo: modelTo, modelTo: modelTo,
properties: params.properties properties: params.properties,
options: params.options
}); });
modelFrom.dataSource.defineForeignKey(modelTo.modelName, fk, modelFrom.modelName); modelFrom.dataSource.defineForeignKey(modelTo.modelName, fk, modelFrom.modelName);