/** * Create a new belongs to relationship instance. * * @param \Database\ORM\Builder $query * @param \Database\ORM\Model $parent * @param string $foreignKey * @param string $otherKey * @param string $relation * @return void */ public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $relation) { $this->otherKey = $otherKey; $this->relation = $relation; $this->foreignKey = $foreignKey; parent::__construct($query, $parent); }
/** * Create a new has many relationship instance. * * @param \Database\ORM\Builder $query * @param \Database\ORM\Model $farParent * @param \Database\ORM\Model $parent * @param string $firstKey * @param string $secondKey * @return void */ public function __construct(Builder $query, Model $farParent, Model $parent, $firstKey, $secondKey) { $this->firstKey = $firstKey; $this->secondKey = $secondKey; $this->farParent = $farParent; parent::__construct($query, $parent); }
/** * Get the "has relation" base query instance. * * @param string $relation * @return \Database\ORM\Builder */ protected function getHasRelationQuery($relation) { return Relation::noConstraints(function () use($relation) { return $this->getModel()->{$relation}(); }); }
/** * Add the constraints for a relationship count query. * * @param \Database\ORM\Builder $query * @param \Database\ORM\Builder $parent * @return \Database\ORM\Builder */ public function getRelationCountQuery(Builder $query, Builder $parent) { if ($parent->getQuery()->from == $query->getQuery()->from) { return $this->getRelationCountQueryForSelfJoin($query, $parent); } $this->setJoin($query); return parent::getRelationCountQuery($query, $parent); }
/** * Create a new has many relationship instance. * * @param \Database\ORM\Builder $query * @param \Database\ORM\Model $parent * @param string $foreignKey * @param string $localKey * @return void */ public function __construct(Builder $query, Model $parent, $foreignKey, $localKey) { $this->localKey = $localKey; $this->foreignKey = $foreignKey; parent::__construct($query, $parent); }