diff --git a/src/ORM/Association/BelongsToMany.php b/src/ORM/Association/BelongsToMany.php index a26aceff4f8..09c68e4adce 100644 --- a/src/ORM/Association/BelongsToMany.php +++ b/src/ORM/Association/BelongsToMany.php @@ -960,14 +960,44 @@ function () use ($sourceEntity, $targetEntities, $options) { /** * {@inheritDoc} */ + public function setConditions($conditions) + { + parent::setConditions($conditions); + $this->_targetConditions = $this->_junctionConditions = null; + + return $this; + } + + /** + * {@inheritDoc} + * @deprecated Use setConditions()/getConditions() instead. + */ public function conditions($conditions = null) { if ($conditions !== null) { - $this->_conditions = $conditions; - $this->_targetConditions = $this->_junctionConditions = null; + $this->setConditions($conditions); } - return $this->_conditions; + return $this->getConditions(); + } + + /** + * @param string|\Cake\ORM\Table $through + * @return $this + */ + public function setThrough($through) + { + $this->_through = $through; + + return $this; + } + + /** + * @return string|\Cake\ORM\Table + */ + public function getThrough() + { + return $this->_through; } /** @@ -1410,7 +1440,7 @@ protected function _options(array $opts) $this->_junctionTableName($opts['joinTable']); } if (!empty($opts['through'])) { - $this->_through = $opts['through']; + $this->setThrough($opts['through']); } if (!empty($opts['saveStrategy'])) { $this->saveStrategy($opts['saveStrategy']); diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index e38b2973870..518aefd24b6 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -4126,6 +4126,7 @@ public function testBelongsToManyFluentInterface() ->setSource($authors) ->setStrategy('select') ->setSaveStrategy('append') + ->setThrough('author_articles') ->setJoinType('inner'); }