Beispiel #1
0
 public function __construct(Repo $repo)
 {
     $this->repo = $repo;
     $table = $this->getDb()->escapeName($repo->getTable());
     $this->from($repo->getTable())->column(new SQL("{$table}.*"));
     parent::__construct($repo->getDbInstance());
 }
Beispiel #2
0
 /**
  * @param  Repo $repo
  * @param  array        $rels
  * @param  string       $parent
  */
 private function joinNestedRels(Repo $repo, array $rels, $parent)
 {
     foreach ($rels as $name => $childRels) {
         $rel = $repo->getRelOrError($name);
         $rel->join($this, $parent);
         if ($childRels) {
             $this->joinNestedRels($rel->getRepo(), $childRels, $name);
         }
     }
 }
Beispiel #3
0
 /**
  * Get Links object associated with this model.
  * If there is none, an empty Links object is created.
  *
  * @param  AbstractModel            $model
  * @return Links
  * @throws InvalidArgumentException If model does not belong to repo
  */
 public function get(AbstractModel $model)
 {
     if (!$this->repo->isModel($model)) {
         throw new InvalidArgumentException(sprintf('Model must be %s, was %s', $this->repo->getModelClass(), get_class($model)));
     }
     if ($this->map->contains($model)) {
         return $this->map[$model];
     } else {
         return $this->map[$model] = new Links($model);
     }
 }
Beispiel #4
0
 public function models(Models $models)
 {
     $changes = array();
     foreach ($models as $model) {
         $data = $model->getChanges();
         $model->getRepo()->getSerializers()->serialize($data);
         $changes[$model->getId()] = $data;
     }
     $key = $this->repo->getPrimaryKey();
     $this->setMultiple($changes, $key)->whereIn($key, array_keys($changes));
     return $this;
 }
Beispiel #5
0
 public function __construct(Repo $repo)
 {
     $this->repo = $repo;
     $this->into($repo->getTable());
     parent::__construct($repo->getDbInstance());
 }
Beispiel #6
0
 /**
  * @covers ::newVoidModel
  */
 public function testNewVoidModel()
 {
     $repo = new Repo(new Config(__NAMESPACE__ . '\\TestModel\\City'));
     $model = $repo->newVoidModel();
     $this->assertInstanceOf(__NAMESPACE__ . '\\TestModel\\City', $model);
     $this->assertTrue($model->isVoid());
     $model = $repo->newVoidModel(['id' => 10, 'name' => 'new']);
     $this->assertEquals(['id' => 10, 'name' => 'new', 'countryId' => null], $model->getProperties());
     $this->assertTrue($model->isVoid());
 }