Fix schema references

This commit is contained in:
Raymond Feng 2013-07-23 12:16:12 -07:00
parent 9b169efc8c
commit 4df5a02676
2 changed files with 34 additions and 33 deletions

View File

@ -473,7 +473,7 @@ DataSource.prototype.discoverModelPropertiesSync = function (modelName, options)
* Discover primary keys for a given owner/modelName
*
* Each primary key column description has the following columns:
* owner String => table dataSource (may be null)
* owner String => table schema (may be null)
* tableName String => table name
* columnName String => column name
* keySeq Number => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
@ -503,12 +503,12 @@ DataSource.prototype.discoverPrimaryKeysSync= function(modelName, options) {
/**
* Discover foreign keys for a given owner/modelName
*
* fkOwner String => foreign key table dataSource (may be null)
* fkOwner String => foreign key table schema (may be null)
* fkName String => foreign key name (may be null)
* fkTableName String => foreign key table name
* fkColumnName String => foreign key column name
* keySeq short => sequence number within a foreign key( a value of 1 represents the first column of the foreign key, a value of 2 would represent the second column within the foreign key).
* pkOwner String => primary key table dataSource being imported (may be null)
* pkOwner String => primary key table schema being imported (may be null)
* pkName String => primary key name (may be null)
* pkTableName String => primary key table name being imported
* pkColumnName String => primary key column name being imported
@ -539,12 +539,12 @@ DataSource.prototype.discoverForeignKeysSync= function(modelName, options) {
* Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table).
* They are ordered by fkTableOwner, fkTableName, and keySeq.
*
* fkOwner String => foreign key table dataSource (may be null)
* fkOwner String => foreign key table schema (may be null)
* fkName String => foreign key name (may be null)
* fkTableName String => foreign key table name
* fkColumnName String => foreign key column name
* keySeq short => sequence number within a foreign key( a value of 1 represents the first column of the foreign key, a value of 2 would represent the second column within the foreign key).
* pkOwner String => primary key table dataSource being imported (may be null)
* pkOwner String => primary key table schema being imported (may be null)
* pkName String => primary key name (may be null)
* pkTableName String => primary key table name being imported
* pkColumnName String => primary key column name being imported
@ -613,7 +613,7 @@ DataSource.prototype.discoverSchema = function (modelName, options, cb) {
}
/**
* Discover dataSource from a given modelName/view
* Discover schema from a given modelName/view
*
* @param modelName
* @param cb
@ -627,7 +627,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
}
var self = this;
var dataSourceName = this.name || this.connector.name;
var schemaName = this.name || this.connector.name;
var tasks = [
this.discoverModelProperties.bind(this, modelName, options),
@ -661,7 +661,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
console.log('Primary keys: ', pks);
}
var dataSource = {
var schema = {
name: fromDBName(modelName, false),
options: {
idInjection: false // DO NOT add id property
@ -670,8 +670,8 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
}
};
dataSource.options[dataSourceName] = {
dataSource: columns[0].owner,
schema.options[schemaName] = {
schema: columns[0].owner,
table: modelName
};
@ -679,16 +679,16 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
var i = item;
var propName = fromDBName(item.columnName, true);
dataSource.properties[propName] = {
schema.properties[propName] = {
type: item.type,
required: (item.nullable === 'N'),
length: item.dataLength
};
if (pks[item.columnName]) {
dataSource.properties[propName].id = pks[item.columnName];
schema.properties[propName].id = pks[item.columnName];
}
dataSource.properties[propName][dataSourceName] = {
schema.properties[propName][schemaName] = {
columnName: i.columnName,
dataType: i.dataType,
dataLength: i.dataLength,
@ -701,9 +701,9 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
var schemaKey = columns[0].owner + '.' + modelName;
if (!options.visited.hasOwnProperty(schemaKey)) {
if(self.settings.debug) {
console.log('Adding dataSource for ' + schemaKey);
console.log('Adding schema for ' + schemaKey);
}
options.visited[schemaKey] = dataSource;
options.visited[schemaKey] = schema;
}
var otherTables = {};
@ -731,7 +731,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
foreignKeys.forEach(function (fk) {
var propName = fromDBName(fk.pkTableName, true);
dataSource.properties[propName] = {
schema.properties[propName] = {
type: fromDBName(fk.pkTableName, false),
association: {
type: 'belongsTo',
@ -752,7 +752,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
var moreTasks = [];
for (var t in otherTables) {
if(self.settings.debug) {
console.log('Discovering related dataSource for ' + schemaKey);
console.log('Discovering related schema for ' + schemaKey);
}
var newOptions = {};
for(var key in options) {
@ -772,14 +772,14 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
/**
* Discover dataSource from a given table/view
* Discover schema from a given table/view
*
* @param modelName
* @param cb
*/
DataSource.prototype.discoverSchemasSync = function (modelName, options) {
var self = this;
var dataSourceName = this.name || this.connector.name;
var schemaName = this.name || this.connector.name;
var columns = this.discoverModelPropertiesSync(modelName, options);
if (!columns || columns.length === 0) {
@ -797,7 +797,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
console.log('Primary keys: ', pks);
}
var dataSource = {
var schema = {
name: fromDBName(modelName, false),
options: {
idInjection: false // DO NOT add id property
@ -806,8 +806,8 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
}
};
dataSource.options[dataSourceName] = {
dataSource: columns.length > 0 && columns[0].owner,
schema.options[schemaName] = {
schema: columns.length > 0 && columns[0].owner,
table: modelName
};
@ -815,16 +815,16 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
var i = item;
var propName = fromDBName(item.columnName, true);
dataSource.properties[propName] = {
schema.properties[propName] = {
type: item.type,
required: (item.nullable === 'N'),
length: item.dataLength
};
if (pks[item.columnName]) {
dataSource.properties[propName].id = pks[item.columnName];
schema.properties[propName].id = pks[item.columnName];
}
dataSource.properties[propName][dataSourceName] = {
schema.properties[propName][schemaName] = {
columnName: i.columnName,
dataType: i.dataType,
dataLength: i.dataLength,
@ -837,9 +837,9 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
var schemaKey = columns[0].owner + '.' + modelName;
if (!options.visited.hasOwnProperty(schemaKey)) {
if (self.settings.debug) {
console.log('Adding dataSource for ' + schemaKey);
console.log('Adding schema for ' + schemaKey);
}
options.visited[schemaKey] = dataSource;
options.visited[schemaKey] = schema;
}
var otherTables = {};
@ -867,7 +867,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
foreignKeys.forEach(function (fk) {
var propName = fromDBName(fk.pkTableName, true);
dataSource.properties[propName] = {
schema.properties[propName] = {
type: fromDBName(fk.pkTableName, false),
association: {
type: 'belongsTo',
@ -888,7 +888,7 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
var moreTasks = [];
for (var t in otherTables) {
if (self.settings.debug) {
console.log('Discovering related dataSource for ' + schemaKey);
console.log('Discovering related schema for ' + schemaKey);
}
var newOptions = {};
for(var key in options) {
@ -919,8 +919,8 @@ DataSource.prototype.discoverAndBuildModels = function (modelName, options, cb)
var schemaList = [];
for (var s in schemas) {
var dataSource = schemas[s];
schemaList.push(dataSource);
var schema = schemas[s];
schemaList.push(schema);
}
var models = self.buildModels(schemaList);
@ -939,8 +939,8 @@ DataSource.prototype.discoverAndBuildModelsSync = function (modelName, options)
var schemaList = [];
for (var s in schemas) {
var dataSource = schemas[s];
schemaList.push(dataSource);
var schema = schemas[s];
schemaList.push(schema);
}
var models = this.buildModels(schemaList);

View File

@ -128,6 +128,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
ModelClass.setMaxListeners = events.setMaxListeners.bind(events);
hiddenProperty(ModelClass, 'dataSource', dataSource);
hiddenProperty(ModelClass, 'schema', dataSource); // For backward compatibility
hiddenProperty(ModelClass, 'modelName', className);
hiddenProperty(ModelClass, 'pluralModelName', pluralName || i8n.pluralize(className));
hiddenProperty(ModelClass, 'relations', {});