For example, parentModel is Users and foreignModel is Articles. Each user has zero or more articles.
상속: extends FOF30\Model\DataModel\Relation
예제 #1
0
파일: HasManyTest.php 프로젝트: Joal01/fof
 /**
  * @group           HasMany
  * @group           HasManyGetNew
  * @covers          FOF30\Model\DataModel\Relation\HasMany::getNew
  */
 public function testGetNew()
 {
     $model = $this->buildModel();
     $model->find(2);
     $relation = new HasMany($model, 'Children');
     $new = $relation->getNew();
     $this->assertInstanceOf('Fakeapp\\Site\\Model\\Children', $new);
     $this->assertEquals(2, $new->getFieldValue('fakeapp_parent_id'), 'HasMany::getNew Failed to prime the new record');
 }
예제 #2
0
파일: HasOne.php 프로젝트: akeeba/fof
 /**
  * Get the relation data.
  *
  * If you want to apply additional filtering to the foreign model, use the $callback. It can be any function,
  * static method, public method or closure with an interface of function(DataModel $foreignModel). You are not
  * supposed to return anything, just modify $foreignModel's state directly. For example, you may want to do:
  * $foreignModel->setState('foo', 'bar')
  *
  * @param callable   $callback The callback to run on the remote model.
  * @param Collection $dataCollection
  *
  * @return Collection|DataModel
  */
 public function getData($callback = null, Collection $dataCollection = null)
 {
     if (is_null($dataCollection)) {
         return parent::getData($callback, $dataCollection)->first();
     } else {
         return parent::getData($callback, $dataCollection);
     }
 }