Skip to content

Commit

Permalink
allow callable scope
Browse files Browse the repository at this point in the history
  • Loading branch information
quickapps authored and lorenzo committed Mar 29, 2014
1 parent 2de96b1 commit fe05b8d
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Model/Behavior/TreeBehavior.php
Expand Up @@ -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;
}
}

0 comments on commit fe05b8d

Please sign in to comment.