Skip to content
Browse files

allow overriding table name

  • Loading branch information...
1 parent 0b974a2 commit 62b7c8b343299b4815b9d1aeb83fcaa9cbe347f1 @joeferner committed
Showing with 9 additions and 5 deletions.
  1. +3 −1 README.md
  2. +4 −2 lib/model.js
  3. +2 −2 lib/persist.js
View
4 README.md
@@ -177,7 +177,7 @@ __Example__
});
<a name="persistDefine" />
-### persist.define(modelName, properties): Model
+### persist.define(modelName, properties, [opts]): Model
Defines a model object for use in persist.
@@ -193,6 +193,8 @@ __Arguments__
* defaultValue - this can be a value or a function that will be called each time this model object is created
* dbColumnName - the name of the database column. (default: name of the property, all lower case, seperated by '_')
* primaryKey - Marks this column as being the primary key column. You can have only one primary key column.
+ * opts - Options for this column.
+ * tableName - The name of the table (default: modelName pluralized).
__Returns__
View
6 lib/model.js
@@ -154,7 +154,9 @@ function addColumns (model, columnDefs) {
ensurePrimaryKeyColumn(model);
}
-exports.define = function (name, columnDefs) {
+exports.define = function (name, columnDefs, opts) {
+ opts = opts || {};
+
var Model = function (values) {
this._getModel = function () { return Model; }; // hide from JSON.stringify
@@ -209,7 +211,7 @@ exports.define = function (name, columnDefs) {
};
Model.modelName = name;
- Model.tableName = inflection.pluralize(name);
+ Model.tableName = opts.tableName || inflection.pluralize(name);
Model.associations = {};
Model.columns = {};
View
4 lib/persist.js
@@ -19,8 +19,8 @@ exports.env = null;
var databaseJsonLoaded = false;
var defaultConnectOptions = null;
-exports.define = function(name, columnDefs) {
- return Model.define(name, columnDefs);
+exports.define = function(name, columnDefs, opts) {
+ return Model.define(name, columnDefs, opts);
};
exports.asyncQueue = function() {

0 comments on commit 62b7c8b

Please sign in to comment.
Something went wrong with that request. Please try again.