Example of Users\Row namespace Application\Users; class Row extends \Bluz\Db\Row { public function beforeInsert() { $this->created = gmdate('Y-m-d H:i:s'); } public function beforeUpdate() { $this->updated = gmdate('Y-m-d H:i:s'); } } $userRow = new \Application\Users\Row(); $userRow -> login = 'username'; $userRow -> save();
Author: Anton Shevchuk
Inheritance: implements JsonSerializable, implements ArrayAccess, use trait Bluz\Common\Container\Container, use trait Bluz\Common\Container\ArrayAccess, use trait Bluz\Common\Container\JsonSerialize, use trait Bluz\Common\Container\MagicAccess
Ejemplo n.º 1
0
 /**
  * findRelation
  *
  * @param  Row $row
  * @param  string $relation
  * @return array
  * @throws Exception\RelationNotFoundException
  */
 public static function findRelation($row, $relation)
 {
     $model = $row->getTable()->getModel();
     /** @var \Bluz\Db\Table $relationTable */
     $relationTable = Relations::getModelClass($relation);
     $relationTable::getInstance();
     if (!($relations = Relations::getRelations($model, $relation))) {
         throw new RelationNotFoundException("Relations between model `{$model}` and `{$relation}` is not defined");
     }
     // check many-to-many relations
     if (sizeof($relations) == 1) {
         $relations = Relations::getRelations($model, current($relations));
     }
     $field = $relations[$model];
     $key = $row->{$field};
     return Relations::findRelations($model, $relation, [$key]);
 }
Ejemplo n.º 2
0
 /**
  * Set relation
  * @param Row $row
  * @return Row
  */
 public function setRelation(Row $row)
 {
     $modelName = $row->getTable()->getModel();
     $this->relations[$modelName] = [$row];
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * @expectedException Bluz\Db\Exception\RelationNotFoundException
  */
 public function testGetRelationException()
 {
     $this->row->getRelation('wrongRelation');
 }