/** * @param string $class * @param ORM $orm * @param Loader $loader */ public function __construct($class, ORM $orm = null, Loader $loader = null) { $this->class = $class; $this->orm = $this->saturate($orm, ORM::class); $this->columns = $this->dataColumns = []; //We aways need primary loader if (empty($this->loader = $loader)) { //Selector always need primary data loaded to define data structure and perform query //parsing, in most of cases we can easily use RootLoader associated with primary record //schema $this->loader = new RootLoader($this->orm, null, $this->orm->schema($class)); } //Every ORM loader has ability to declare it's primary database, we are going to use //primary loader database to initiate selector $database = $this->loader->dbalDatabase(); //AbstractSelect construction parent::__construct($database, $database->driver()->queryCompiler($database->getPrefix())); }
/** * {@inheritdoc} */ public function getParameters(QueryCompiler $compiler = null) { $parameters = parent::getParameters($compiler = !empty($compiler) ? $compiler : $this->compiler->reset()); //Unions always located at the end of query. foreach ($this->unions as $union) { if ($union[0] instanceof QueryBuilder) { $parameters = array_merge($parameters, $union[0]->getParameters($compiler)); } } return $parameters; }
/** * {@inheritdoc} */ public function count($column = self::DEFAULT_COUNTING_FIELD) { if ($column == self::DEFAULT_COUNTING_FIELD && !empty($this->loader->getPrimaryKey())) { $column = 'DISTINCT(' . $this->loader->getPrimaryKey() . ')'; } return parent::count($column); }