- Added a new RelationTypeEnum

This commit is contained in:
mcndave committed 2023-02-07 16:49:25 +00:00
1 parent 26ffecbb6e
commit 94edb09352
4 files changed
+24 -8

No files matched your search

+4 -5
View File
@@ -7,7 +7,7 @@ use Ulmus\Attribute\Attribute;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Relation {
public function __construct(
public string $type,
public Relation\RelationTypeEnum|string $type,
public \Stringable|string|array $key = "",
public null|\Closure $generateKey = null,
public null|\Stringable|string|array $foreignKey = null,
@@ -29,7 +29,6 @@ class Relation {
$this->bridgeField = Attribute::handleArrayField($this->bridgeField);
$this->bridgeForeignKey = Attribute::handleArrayField($this->bridgeForeignKey);
$this->field = Attribute::handleArrayField($this->field);
}
public function entity() {
@@ -55,17 +54,17 @@ class Relation {
public function isOneToOne() : bool
{
return $this->normalizeType() === 'onetoone';
return $this->type === Relation\RelationTypeEnum::oneToOne || $this->normalizeType() === 'onetoone';
}
public function isOneToMany() : bool
{
return $this->normalizeType() === 'onetomany';
return $this->type === Relation\RelationTypeEnum::oneToMany || $this->normalizeType() === 'onetomany';
}
public function isManyToMany() : bool
{
return $this->normalizeType() === 'manytomany';
return $this->type === Relation\RelationTypeEnum::manyToMany || $this->normalizeType() === 'manytomany';
}
public function function() : string