Skip to content

Commit

Permalink
Merge pull request #490 from AndrewBarba/master
Browse files Browse the repository at this point in the history
Accept table options when creating a model - PR by @AndrewBarba
  • Loading branch information
neumino committed Apr 29, 2016
2 parents b0010f1 + dd2e038 commit 7224490
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function Model(name, schema, options, thinky) {

this._pk = (options.pk != null) ? options.pk : 'id';

this._table = (options.table != null) ? options.table : {};
this._table.primaryKey = this._pk;

this._thinky = thinky;

this._validator = options.validator;
Expand Down Expand Up @@ -202,7 +205,7 @@ Model.prototype.tableReady = function() {
var r = model._thinky.r;
this._tableReadyPromise = model._thinky.dbReady()
.then(function() {
return r.tableCreate(model._name, {primaryKey: model._pk}).run();
return r.tableCreate(model._name, model._table).run();
})
.error(function(error) {
if (error.message.match(/Table `.*` already exists/)) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thinky",
"version": "2.3.0",
"version": "2.3.1",
"description": "RethinkDB ORM for Node.js",
"main": "lib/thinky.js",
"directories": {
Expand All @@ -26,7 +26,7 @@
"dependencies":{
"rethinkdbdash": "~2.3.0",
"bluebird": "~2.10.2",
"validator": "~ 3.22.1"
"validator": "~3.22.1"
},
"devDependencies": {
"mocha": "~1.21.5"
Expand Down
14 changes: 14 additions & 0 deletions test/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ describe('Options', function(){
});
});
});
it('table option on a model', function(done){
var name = util.s8();
var Model = thinky.createModel(name, {id: String, name: String}, {
table: {
durability: 'soft'
}
});
Model.once('ready', function() {
r.table(Model.getTableName()).config().run().then(function(result) {
assert.equal(result.durability, 'soft');
done();
});
});
});
it('Options on a document', function(){
var name = util.s8();
var Model = thinky.createModel(name, {id: String, name: String});
Expand Down

0 comments on commit 7224490

Please sign in to comment.