Extract the relation types
This commit is contained in:
parent
89a30e7edd
commit
580ce14f0d
|
@ -310,6 +310,8 @@ function isModelClass(cls) {
|
||||||
return cls.prototype instanceof ModelBaseClass;
|
return cls.prototype instanceof ModelBaseClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataSource.relationTypes = ['belongsTo', 'hasMany', 'hasAndBelongsToMany'];
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Define relations for the model class from the relations object
|
* Define relations for the model class from the relations object
|
||||||
* @param modelClass
|
* @param modelClass
|
||||||
|
@ -357,7 +359,7 @@ DataSource.prototype.defineRelations = function(modelClass, relations) {
|
||||||
if (relations) {
|
if (relations) {
|
||||||
for (var rn in relations) {
|
for (var rn in relations) {
|
||||||
var r = relations[rn];
|
var r = relations[rn];
|
||||||
assert(['belongsTo', 'hasMany', 'hasAndBelongsToMany'].indexOf(r.type) !== -1, "Invalid relation type: " + r.type);
|
assert(DataSource.relationTypes.indexOf(r.type) !== -1, "Invalid relation type: " + r.type);
|
||||||
var targetModel = isModelClass(r.model) ? r.model : this.models[r.model];
|
var targetModel = isModelClass(r.model) ? r.model : this.models[r.model];
|
||||||
if (!targetModel) {
|
if (!targetModel) {
|
||||||
// The target model doesn't exist, let create a place holder for it
|
// The target model doesn't exist, let create a place holder for it
|
||||||
|
|
Loading…
Reference in New Issue