1602 / jugglingdb

Multi-database ORM for nodejs: redis, mongodb, mysql, sqlite3, postgresql, arango, in-memory...
http://1602.github.io/jugglingdb/
2.04k stars 241 forks source link

Add option to skip validation when saving new model #315

Closed absynce closed 11 years ago

absynce commented 11 years ago

Previously, if a new instance of a model calls save({ validate: false }, validation still occurred because it was calling Model.create.

I've added the ability to pass the option to validate to the Model.create via the data parameter.

For example:

var p = new Person();
p.validatesPresenceOf('name');
p.isValid().should.be.false;
p.isNewRecord().should.be.true;
p.save({ validate: false }, function (err) {
    should.not.exist(err);
    p.isNewRecord().should.be.false;
});

I included the test for this case as well.

P.S. I know passing the data into the data parameter looks odd when it is then set via data = data.data;, but I couldn't think of a better name and didn't want to rename the existing parameter. Ideas are welcome.

absynce commented 11 years ago

This test is necessary because it is a different case. The test before it calls a save on an existing record, which works fine. This test skips validation when a new record is saved.

anatoliychakkaev commented 11 years ago

I understand that. I'm talking about stub you're using within your test. It looks incorrect.

On Tue, Aug 20, 2013 at 7:05 PM, Jared M. Smith notifications@github.comwrote:

This test is necessary because it is a different case. The test before ithttps://github.com/absynce/jugglingdb/blob/93542c3df01947014ce30534541213b7a8981ba3/test/manipulation.test.js#L145-L163calls a save on an existing record, which works fine. This test skips validation when a new record is saved.

— Reply to this email directly or view it on GitHubhttps://github.com/1602/jugglingdb/pull/315#issuecomment-22951551 .