diff --git a/Changelog.md b/Changelog.md index 563ce79..0c96f84 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +### v2.2.0 +- Singleton/cache disabled by default (#672) + ### v2.1.27 - Fix noisy mysql debug output (#642) diff --git a/Readme.md b/Readme.md index 3a9fc57..c55cb64 100755 --- a/Readme.md +++ b/Readme.md @@ -70,7 +70,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) { }); // add the table to the database - db.sync(function(err) { + db.sync(function(err) { if (err) throw err; // add a row to the person table @@ -90,7 +90,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) { // err.msg = "under-age"; }); }); - + }); }); }); @@ -278,7 +278,7 @@ var Person = db.define("person", { Other options: -- `cache` : (default: `true`) Set it to `false` to disable Instance cache ([Singletons](#singleton)) or set a timeout value (in seconds); +- `cache` : (default: `false`) Set it to `true` to enable Instance cache ([Singletons](#singleton)) or set a timeout value (in seconds); - `autoSave` : (default: `false`) Set it to `true` to save an Instance right after changing any property; - `autoFetch` : (default: `false`) Set it to `true` to fetch associations when fetching an instance from the database; - `autoFetchLimit` : (default: `1`) If `autoFetch` is enabled this defines how many hoops (associations of associations) @@ -516,16 +516,16 @@ db.driver.execQuery( ### Caching & Integrity -Model instances are cached. If multiple different queries will result in the same result, you will +Model instances can be cached (turned off by default). If enabled, multiple different queries will result in the same result - you will get the same object. If you have other systems that can change your database (or you're developing and need -to make some manual changes) you should remove this feature by disabling cache. This can be done when you're -defining the Model. +to make some manual changes) you shouldn't use this feature. +It can be enabled/disabled per model: ```js var Person = db.define('person', { name : String }, { - cache : false + cache : true }); ``` @@ -533,7 +533,7 @@ and also globally: ```js orm.connect('...', function(err, db) { - db.settings.set('instance.cache', false); + db.settings.set('instance.cache', true); }); ``` diff --git a/lib/Settings.js b/lib/Settings.js index 1fddd38..c054a67 100644 --- a/lib/Settings.js +++ b/lib/Settings.js @@ -6,7 +6,7 @@ var default_settings = { required : false }, instance : { - cache : true, + cache : false, cacheSaveCheck : true, autoSave : false, autoFetch : false, diff --git a/package.json b/package.json index 1b16927..caaf017 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ "lodash" : "2.4.1" }, "devDependencies": { - "mysql" : "2.5.5", - "pg" : "4.3.0", - "sqlite3" : "3.0.5", + "mysql" : "2.9.0", + "pg" : "4.4.3", + "sqlite3" : "3.1.0", "async" : "0.9.0", "mocha" : "1.13.0", "should" : "1.2.2", diff --git a/test/integration/association-hasone-reverse.js b/test/integration/association-hasone-reverse.js index 2dea61c..19fb9b3 100644 --- a/test/integration/association-hasone-reverse.js +++ b/test/integration/association-hasone-reverse.js @@ -153,7 +153,11 @@ describe("hasOne", function () { it("should be able to set an array of people as the owner", function (done) { Person.find({ name: ["John Doe", "Jane Doe"] }, function (err, owners) { + should.not.exist(err); + Pet.find({ name: "Fido" }).first(function (err, Fido) { + should.not.exist(err); + Fido.hasOwners(function (err, has_owner) { should.not.exist(err); has_owner.should.be.false; @@ -166,7 +170,10 @@ describe("hasOne", function () { should(Array.isArray(owners)); owners.length.should.equal(2); - if (owners[0] == ownersCopy[0]) { + // Don't know which order they'll be in. + var idProp = common.protocol() == 'mongodb' ? '_id' : 'id' + + if (owners[0][idProp] == ownersCopy[0][idProp]) { owners[0].should.eql(ownersCopy[0]); owners[1].should.eql(ownersCopy[1]); } else { diff --git a/test/mocha.opts b/test/mocha.opts index 5ada47b..c807f3b 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1,2 @@ --reporter spec +--timeout 5000