From 580ce14f0ddec13ccb573f150ebb1e056ca9ce94 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 7 Nov 2013 13:30:54 -0800 Subject: [PATCH] Extract the relation types --- lib/datasource.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/datasource.js b/lib/datasource.js index a7f9005f..be663cbf 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -310,6 +310,8 @@ function isModelClass(cls) { return cls.prototype instanceof ModelBaseClass; } +DataSource.relationTypes = ['belongsTo', 'hasMany', 'hasAndBelongsToMany']; + /*! * Define relations for the model class from the relations object * @param modelClass @@ -357,7 +359,7 @@ DataSource.prototype.defineRelations = function(modelClass, relations) { if (relations) { for (var rn in relations) { 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]; if (!targetModel) { // The target model doesn't exist, let create a place holder for it