/**
  * @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()));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function __construct(ORM $orm, $container, array $definition = [], LoaderInterface $parent = null)
 {
     $this->orm = $orm;
     //Related record schema
     $this->schema = $orm->schema($definition[static::RELATION_TYPE]);
     $this->container = $container;
     $this->definition = $definition;
     $this->parent = $parent;
     //Compiling options
     $this->options['method'] = static::LOAD_METHOD;
     if (!empty($parent)) {
         if (!$parent instanceof Loader || $parent->getDatabase() != $this->getDatabase()) {
             //We have to force post-load (separate query) if parent loader database is different
             $this->options['method'] = self::POSTLOAD;
         }
     }
     $this->dataColumns = array_keys($this->schema[ORM::M_COLUMNS]);
 }
Esempio n. 3
0
 /**
  * Due setContext() method and entity cache of ORM any custom initiation code in constructor
  * must not depends on database data.
  *
  * @see setContext
  * @param array      $data
  * @param bool|false $loaded
  * @param ORM|null   $orm
  * @param array      $ormSchema
  * @throws SugarException
  */
 public function __construct(array $data = [], $loaded = false, ORM $orm = null, array $ormSchema = [])
 {
     $this->loaded = $loaded;
     //We can use global container as fallback if no default values were provided
     $this->orm = $this->saturate($orm, ORM::class);
     $this->ormSchema = !empty($ormSchema) ? $ormSchema : $this->orm->schema(static::class);
     if (isset($data[ORM::PIVOT_DATA])) {
         $this->pivotData = $data[ORM::PIVOT_DATA];
         unset($data[ORM::PIVOT_DATA]);
     }
     foreach (array_intersect_key($data, $this->ormSchema[ORM::M_RELATIONS]) as $name => $relation) {
         $this->relations[$name] = $relation;
         unset($data[$name]);
     }
     parent::__construct($data + $this->ormSchema[ORM::M_COLUMNS], $this->ormSchema);
     if (!$this->isLoaded()) {
         //Non loaded records should be in solid state by default and require initial validation
         $this->solidState(true)->invalidate();
     }
 }