/** * Set up the simplest initial query */ public function initialiseQuery() { // Get the tables to join to. // Don't get any subclass tables - let lazy loading do that. $tableClasses = ClassInfo::ancestry($this->dataClass, true); // Error checking if (!$tableClasses) { if (!SS_ClassLoader::instance()->hasManifest()) { user_error("DataObjects have been requested before the manifest is loaded. Please ensure you are not" . " querying the database in _config.php.", E_USER_ERROR); } else { user_error("DataList::create Can't find data classes (classes linked to tables) for" . " {$this->dataClass}. Please ensure you run dev/build after creating a new DataObject.", E_USER_ERROR); } } $baseClass = array_shift($tableClasses); // Build our intial query $this->query = new SQLSelect(array()); $this->query->setDistinct(true); if ($sort = singleton($this->dataClass)->stat('default_sort')) { $this->sort($sort); } $this->query->setFrom("\"{$baseClass}\""); $obj = Injector::inst()->get($baseClass); $obj->extend('augmentDataQueryCreation', $this->query, $this); }
/** * Set whether this query should be distinct or not. * * @param bool $value * @return DataQuery */ public function distinct($value) { $this->query->setDistinct($value); return $this; }