Beispiel #1
0
 private function _addRelation(Relation $relation)
 {
     $name = $relation->getName();
     if (isset($this->_relations[$name])) {
         throw new InvalidArgumentException("{$this->modelClass} already has a relation: {$name}");
     }
     $this->_relations[$name] = $relation;
 }
Beispiel #2
0
 public function asJoinClause()
 {
     $joinedModel = $this->relation->getRelationModelObject();
     $joinTable = $joinedModel->getTableName();
     $joinKey = $this->relation->getForeignKey();
     $idName = $this->relation->getLocalKey();
     $onClauses = array(WhereClause::create($this->on), $this->relation->getCondition());
     return new JoinClause($joinTable, $joinKey, $idName, $this->fromTable, $this->alias, $this->type, $onClauses);
 }
 /**
  * @test
  */
 public function shouldJoinInlineRelation()
 {
     //given
     $product = Product::create(array('name' => 'sony'));
     $orderProduct = OrderProduct::create(array('id_product' => $product->getId()));
     //when
     $fetched = Product::join(Relation::inline(array('destinationField' => 'orderProduct', 'class' => 'Test\\OrderProduct', 'foreignKey' => 'id_product', 'localKey' => 'id')))->fetch();
     //then
     $this->assertEquals($orderProduct, self::getNoLazy($fetched, 'orderProduct'));
 }