Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/adapters/sql/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ var utils = require('utilities')
module.exports = new (function () {
this.COLUMN_NAME_DELIMITER = '"';

/**
* Get the TableName of the Model. First checks if it
* was defined on the model, otherwise it performs a pluralization of
* the model name
*
* @param {string} name - the name of the model
* @returns {model.ModelDescription.tableName|string}
* @private
*/
this._tableizeModelName = function (name) {
return utils.string.getInflection(name, 'filename', 'plural');
// Get the Correct model name (in case the name is passed in with the wrong case)
var modelName = utils.string.getInflection(name, 'constructor', 'singular');

return (model.descriptionRegistry[modelName] && model.descriptionRegistry[modelName].tableName)
|| utils.string.getInflection(name, 'filename', 'plural');
};

this._modelizeTableName = function (name, ownerName) {
var modelName
, ownerModelName
, ownerModelName;
modelName = utils.string.getInflection(name, 'constructor', 'singular');
if (ownerName && name != ownerName) {
ownerModelName = utils.string.getInflection(ownerName, 'constructor', 'singular');
Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ utils.mixin(model, new (function () {
ModelDefinition.prototype = new model.ModelDefinitionBase(name);
defined = new ModelDefinition();

// Set the table name from the instance or model definition
model.descriptionRegistry[name].tableName = defined.tableName || (ModelDefinition.tableName || null);

// Create the constructor function to use when calling static
// ModelCtor.create. Gives them the proper instanceof value,
// and .valid, etc. instance-methods.
Expand Down Expand Up @@ -907,6 +910,7 @@ model.ModelDefinitionBase = function (name) {
};

this.name = name;
this.tableName = null;

this.setAdapter = function (name, config) {
var adapter = adapters.create(name, config);
Expand Down Expand Up @@ -1055,6 +1059,7 @@ model.ModelDescription = function (name) {
this.name = name;
this.properties = {};
this.associations = {};
this.tableName = null;
};

model.PropertyDescription = function (name, datatype, o) {
Expand Down