- WIP on relations, constrains and foreign keys

This commit is contained in:
mcndave committed 2023-07-14 19:57:29 -04:00
1 parent 01ab6e82d4
commit d01624b8aa
8 files changed
+90 -30

No files matched your search

+5 -16
View File
@@ -3,6 +3,7 @@
namespace Ulmus\Attribute\Property\Field;
use Ulmus\Attribute\Attribute;
use Ulmus\Attribute\ConstrainActionEnum;
/**
* Since we need consistancy between the declaration of our ID and FK fields, it
@@ -10,17 +11,6 @@ use Ulmus\Attribute\Attribute;
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class ForeignKey extends PrimaryKey {
public const SET_NULL = "null";
public const SET_DEFAULT = "default";
public const RESTRICT = "restrict";
public const NO_ACTION = "noaction";
public const CASCADE = "cascade";
public function __construct(
public ? string $name = null,
public ? string $type = 'bigint',
@@ -33,11 +23,10 @@ class ForeignKey extends PrimaryKey {
public bool $nullable = false,
public mixed $default = null,
public bool $readonly = false,
public null|array|string|\Stringable $foreignKey = "",
public null|array|string|\Stringable $references = null,
public null|string $onDelete = self::NO_ACTION,
public null|string $onUpdate = self::NO_ACTION,
public null|string $relation = null,
public ConstrainActionEnum $onDelete = ConstrainActionEnum::NoAction,
public ConstrainActionEnum $onUpdate = ConstrainActionEnum::NoAction,
) {
$this->references = Attribute::handleArrayField($this->references, false);
#$this->references = Attribute::handleArrayField($this->references, false);
}
}
+4 -13
View File
@@ -2,20 +2,11 @@
namespace Ulmus\Attribute\Property;
use Ulmus\Attribute\IndexTypeEnum;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Index {
public const TYPE_PRIMARY = 'primary';
public const TYPE_INDEX = 'index';
public const TYPE_UNIQUE = 'unique';
public const TYPE_SPATIAL = 'spatial';
public const TYPE_FULLTEXT = 'fulltext';
public function __construct(
public string $type = self::TYPE_INDEX,
public IndexTypeEnum $type = IndexTypeEnum::Index,
) {}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Ulmus\Attribute\Property;
use Ulmus\Attribute\IndexTypeEnum;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Unique {
public function __construct(
public IndexTypeEnum $type = IndexTypeEnum::Unique,
) {}
}