getReferencedTable() public method

Returns referenced row.
public getReferencedTable ( ActiveRow $row, $table, $column = NULL ) : ActiveRow | null | FALSE
$row ActiveRow
return ActiveRow | null | FALSE NULL if the row does not exist, FALSE if the relationship does not exist
Beispiel #1
0
 public function &__get($key)
 {
     if (array_key_exists($key, $this->data)) {
         $this->access($key);
         return $this->data[$key];
     }
     $column = $this->table->connection->databaseReflection->getReferencedColumn($key, $this->table->name);
     if (array_key_exists($column, $this->data)) {
         $value = $this->data[$column];
         $referenced = $this->table->getReferencedTable($key);
         $ret = isset($referenced[$value]) ? $referenced[$value] : NULL;
         // referenced row may not exist
         return $ret;
     }
     $this->access($key);
     if (array_key_exists($key, $this->data)) {
         return $this->data[$key];
     } else {
         $this->access($key, TRUE);
         $this->access($column);
         if (array_key_exists($column, $this->data)) {
             $value = $this->data[$column];
             $referenced = $this->table->getReferencedTable($key);
             $ret = isset($referenced[$value]) ? $referenced[$value] : NULL;
             // referenced row may not exist
         } else {
             $this->access($column, TRUE);
             trigger_error("Unknown column {$key}", E_USER_WARNING);
             $ret = NULL;
         }
         return $ret;
     }
 }
Beispiel #2
0
	protected function getReference($table, $column)
	{
		$this->accessColumn($column);
		if (array_key_exists($column, $this->data)) {
			$value = $this->data[$column];
			$referenced = $this->table->getReferencedTable($table, $column, $value);
			return isset($referenced[$value]) ? $referenced[$value] : NULL; // referenced row may not exist
		}

		return FALSE;
	}
Beispiel #3
0
 public function &__get($key)
 {
     $this->accessColumn($key);
     if (array_key_exists($key, $this->data)) {
         return $this->data[$key];
     }
     $referenced = $this->table->getReferencedTable($this, $key);
     if ($referenced !== FALSE) {
         $this->accessColumn($key, FALSE);
         return $referenced;
     }
     $this->removeAccessColumn($key);
     throw new Nette\MemberAccessException("Cannot read an undeclared column '{$key}'.");
 }
Beispiel #4
0
 /**
  * @param  string
  * @return ActiveRow|mixed
  * @throws Nette\MemberAccessException
  */
 public function &__get($key)
 {
     if ($this->accessColumn($key)) {
         return $this->data[$key];
     }
     $referenced = $this->table->getReferencedTable($this, $key);
     if ($referenced !== FALSE) {
         $this->accessColumn($key, FALSE);
         return $referenced;
     }
     $this->removeAccessColumn($key);
     $hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($this->data), $key);
     throw new Nette\MemberAccessException("Cannot read an undeclared column '{$key}'" . ($hint ? ", did you mean '{$hint}'?" : '.'));
 }
Beispiel #5
0
 protected function getReference($table, $column)
 {
     if (array_key_exists($column, $this->data)) {
         $this->access($column);
         $value = $this->data[$column];
         $value = $value instanceof ActiveRow ? $value->getPrimary() : $value;
         $referenced = $this->table->getReferencedTable($table, $column, !empty($this->modified[$column]));
         $referenced = isset($referenced[$value]) ? $referenced[$value] : NULL;
         // referenced row may not exist
         if (!empty($this->modified[$column])) {
             // cause saving changed column and prevent regenerating referenced table for $column
             $this->modified[$column] = 0;
             // 0 fails on empty, pass on isset
         }
         return $referenced;
     }
 }