/** * @param string $class * @param ORM $orm * @throws SourceException */ public function __construct($class = null, ORM $orm = null) { if (empty($class)) { if (empty(static::RECORD)) { throw new SourceException("Unable to create source without associate class."); } $class = static::RECORD; } $this->class = $class; $this->orm = $this->saturate($orm, ORM::class); $this->setSelector($this->orm->selector($this->class)); }
/** * Create selector dedicated to load data for current loader. * * @return RecordSelector|null */ public function createSelector() { if (!$this->isLoadable()) { return null; } $selector = $this->orm->selector($this->definition[static::RELATION_TYPE], $this); //Setting columns to be loaded $this->configureColumns($selector); foreach ($this->loaders as $loader) { if ($loader instanceof self) { //Allowing sub loaders to configure required columns and conditions as well $loader->configureSelector($selector); } } foreach ($this->joiners as $joiner) { //Joiners must configure selector as well $joiner->configureSelector($selector); } return $selector; }
/** * Internal ORM relation method used to create valid selector used to pre-load relation data or * create custom query based on relation options. * * Must be redeclarated in child implementations. * * @return RecordSelector */ protected function createSelector() { return $this->orm->selector($this->getClass()); }