From 9bf60e0d743ac5324191af5e9deb9124d8260a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 3 Jun 2016 11:18:57 +0200 Subject: [PATCH] fix --- lib/relation-definition.js | 2 ++ test/include.test.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 31e1cfb9..ee31c1d5 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -1559,6 +1559,8 @@ RelationDefinition.hasAndBelongsToMany = function hasAndBelongsToMany(modelFrom, var options = { as: params.as, through: params.through }; options.properties = params.properties; options.scope = params.scope; + // Forward relation options like "disableInclude" + options.options = params.options; if (params.polymorphic) { var polymorphic = polymorphicParams(params.polymorphic); diff --git a/test/include.test.js b/test/include.test.js index acbb9d59..0d2be343 100644 --- a/test/include.test.js +++ b/test/include.test.js @@ -617,6 +617,29 @@ describe('include', function() { }); }); }); + + it('should support disableInclude for hasAndBelongsToMany', function() { + var Patient = db.define('Patient', { name: String }); + var Doctor = db.define('Doctor', { name: String }); + var DoctorPatient = db.define('DoctorPatient'); + Doctor.hasAndBelongsToMany('patients', { + model: 'Patient', + options: { disableInclude: true }, + }); + + var doctor; + return db.automigrate(['Patient', 'Doctor', 'DoctorPatient']).then(function() { + return Doctor.create({ name: 'Who' }); + }).then(function(inst) { + doctor = inst; + return doctor.patients.create({ name: 'Lazarus' }); + }).then(function() { + return Doctor.find({ include: ['patients'] }); + }).then(function(list) { + list.should.have.length(1); + list[0].toJSON().should.not.have.property('patients'); + }); + }); }); function setup(done) {