Extract the relation types

This commit is contained in:
Raymond Feng 2013-11-07 13:30:54 -08:00
parent 89a30e7edd
commit 580ce14f0d
1 changed files with 3 additions and 1 deletions

View File

@ -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