Example #1
0
 /**
  * Constructor
  * Use $db->createResult( $parent, $name ) instead
  *
  * @param Database|DatabaseTable $parent
  * @param string $name
  *
  * @since 1.0.0
  */
 public function __construct($parent, $name)
 {
     if ($parent instanceof Database) {
         // basic result
         $this->db = $parent;
         $this->table = $this->db->schema()->getAlias($name);
         $this->query = DatabaseQuery::getInstance()->from($this->table);
     } else {
         // result referenced to parent
         $this->parent = $parent;
         $this->db = $parent->getDatabase();
         $this->query = $parent->getDatabaseQuery();
         // determine type of reference based on conventions and user hints
         $this->table = $this->db->schema()->isAlias($name) ? $this->db->schema()->getTable($name) : $name;
         if ($parent->getTable() == $this->table) {
             $this->key = $this->db->schema()->getPrimary($this->getTable());
             $this->parentKey = $this->db->schema()->getReference($parent->getTable(), $name);
         } else {
             $this->key = $this->db->schema()->getBackReference($parent->getTable(), $name);
             $this->parentKey = $this->db->schema()->getPrimary($parent->getTable());
         }
     }
 }