From fe05b8dc6e4a7207191bac25088573f2ed0e7cf8 Mon Sep 17 00:00:00 2001 From: QuickApps Date: Thu, 20 Mar 2014 21:10:10 +0100 Subject: [PATCH] allow callable scope --- src/Model/Behavior/TreeBehavior.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Model/Behavior/TreeBehavior.php b/src/Model/Behavior/TreeBehavior.php index ab5f7b977d1..096ef721f7b 100644 --- a/src/Model/Behavior/TreeBehavior.php +++ b/src/Model/Behavior/TreeBehavior.php @@ -103,17 +103,12 @@ protected function _scope($query) { if (empty($config['scope'])) { return $query; - } - - if (!is_string($config['scope'])) { + } elseif (is_array($config['scope'])) { return $query->where($config['scope']); + } elseif (is_callable($config['scope'])) { + return $config['scope']($query); } - $association = $this->_table->association($query['scope']); - if (!$association) { - throw new \InvalidArgumentException("Invalid association name for 'scope'"); - } - - return $query->matching($association->name()); + return $query; } }