target; } /** * Get an alias. */ public function getAlias(): ?string { return $this->alias; } /** * Get join conditions. */ public function getConditions(): ?WhereItem { return $this->conditions; } public function isTable(): bool { return $this->target[0] === ucfirst($this->target[0]); } public function isRelation(): bool { return !$this->isTable(); } public function isOnlyMiddle(): bool { return $this->onlyMiddle; } /** * Create. * * @param string $target * A relation name or table. A relationName should be in camelCase, a table in CamelCase. * When joining a table, conditions should be specified. * When joining a relation, conditions will be applied automatically. */ public static function create(string $target, ?string $alias = null): self { return new self($target, $alias); } /** * Create with a table target. */ public static function createWithTableTarget(string $table, ?string $alias = null): self { return self::create(ucfirst($table), $alias); } /** * Create with a relation target. Conditions will be applied automatically. */ public static function createWithRelationTarget(string $relation, ?string $alias = null): self { return self::create(lcfirst($relation), $alias); } /** * Clone with an alias. */ public function withAlias(?string $alias): self { $obj = clone $this; $obj->alias = $alias; return $obj; } /** * Clone with join conditions. */ public function withConditions(?WhereItem $conditions): self { $obj = clone $this; $obj->conditions = $conditions; return $obj; } /** * Join only middle table. For many-to-many relationships. */ public function withOnlyMiddle(bool $onlyMiddle = true): self { $obj = clone $this; $obj->onlyMiddle = $onlyMiddle; return $obj; } }