diff --git a/src/Model.php b/src/Model.php index 804a599..87d1d8c 100644 --- a/src/Model.php +++ b/src/Model.php @@ -69,9 +69,14 @@ public function getMetaData() */ public static function on(Connection $db) { - return (new Query()) + $self = new static(); + $query = (new Query()) ->setDb($db) - ->setModel(new static()); + ->setModel($self); + + $self->initQuery($query); + + return $query; } /** @@ -122,6 +127,17 @@ public function createRelations(Relations $relations) { } + /** + * Initialize this model's Query + * + * If you want to initialize the query right after it's construction, override this method + * + * @param Query $query + */ + public function initQuery(Query $query) + { + } + /** * Initialize the model * diff --git a/src/Query.php b/src/Query.php index 8754a5f..6d610da 100644 --- a/src/Query.php +++ b/src/Query.php @@ -312,14 +312,16 @@ public function getUtilize() /** * Add a relation to utilize (join) * - * @param string $path + * @param string|string[] $paths * * @return $this */ - public function utilize($path) + public function utilize($paths) { - $path = $this->getResolver()->qualifyPath($path, $this->getModel()->getTableName()); - $this->utilize[$path] = $this->getResolver()->resolveRelation($path); + foreach ((array) $paths as $path) { + $path = $this->getResolver()->qualifyPath($path, $this->getModel()->getTableName()); + $this->utilize[$path] = $this->getResolver()->resolveRelation($path); + } return $this; }