/** * Get the relation instance for the given relation name. * * @param string $relation * @return \Analogue\ORM\Relationships\Relationship */ public function getRelation($relation) { // We want to run a relationship query without any constrains so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. $query = Relationship::noConstraints(function () use($relation) { return $this->entityMap->{$relation}($this->getEntityInstance()); }); $nested = $this->nestedRelations($relation); // If there are nested relationships set on the query, we will put those onto // the query instances so that they can be handled after this relationship // is loaded. In this way they will all trickle down as they are loaded. if (count($nested) > 0) { $query->getQuery()->with($nested); } return $query; }