From 46dd177be9b50bbdab822b94244c0ba9ffafa164 Mon Sep 17 00:00:00 2001 From: Artur Welp Date: Wed, 19 Aug 2026 10:59:49 -0300 Subject: [PATCH] Moving the relations to a dedicated Namespace --- src/ORM/HasMany.php | 21 --------- src/ORM/HasOne.php | 22 --------- src/ORM/{ => Relations}/BelongsTo.php | 14 +++++- src/ORM/{ => Relations}/BelongsToMany.php | 28 +++++++++++- .../{ => Relations}/BelongsToManyExtended.php | 5 ++- src/ORM/Relations/HasMany.php | 45 +++++++++++++++++++ src/ORM/Relations/HasOne.php | 35 +++++++++++++++ 7 files changed, 124 insertions(+), 46 deletions(-) delete mode 100644 src/ORM/HasMany.php delete mode 100644 src/ORM/HasOne.php rename src/ORM/{ => Relations}/BelongsTo.php (65%) rename src/ORM/{ => Relations}/BelongsToMany.php (67%) rename src/ORM/{ => Relations}/BelongsToManyExtended.php (93%) create mode 100644 src/ORM/Relations/HasMany.php create mode 100644 src/ORM/Relations/HasOne.php diff --git a/src/ORM/HasMany.php b/src/ORM/HasMany.php deleted file mode 100644 index a8a422f..0000000 --- a/src/ORM/HasMany.php +++ /dev/null @@ -1,21 +0,0 @@ -foreignObject = $foreignObject; - $this->remoteField = $remoteField; - $this->localElement = $localElement; - } - - function get() { - return $this->foreignObject::findMany(Array($this->remoteField => Array('=', $this->localElement->id))); - } - -} diff --git a/src/ORM/HasOne.php b/src/ORM/HasOne.php deleted file mode 100644 index 23996eb..0000000 --- a/src/ORM/HasOne.php +++ /dev/null @@ -1,22 +0,0 @@ -foreignObject = $foreignObject; - $this->remoteField = $remoteField; - $this->localElement = $localElement; - } - - function get(){ - return $this->foreignObject::findOne(Array($this->remoteField => Array('=', $this->localElement->id))); - } - -} diff --git a/src/ORM/BelongsTo.php b/src/ORM/Relations/BelongsTo.php similarity index 65% rename from src/ORM/BelongsTo.php rename to src/ORM/Relations/BelongsTo.php index bc48f27..a605fb2 100644 --- a/src/ORM/BelongsTo.php +++ b/src/ORM/Relations/BelongsTo.php @@ -1,7 +1,19 @@ localObject = $localObject; $this->foreignObject = $foreignObject; diff --git a/src/ORM/BelongsToManyExtended.php b/src/ORM/Relations/BelongsToManyExtended.php similarity index 93% rename from src/ORM/BelongsToManyExtended.php rename to src/ORM/Relations/BelongsToManyExtended.php index f0c7e00..369a71b 100644 --- a/src/ORM/BelongsToManyExtended.php +++ b/src/ORM/Relations/BelongsToManyExtended.php @@ -1,6 +1,9 @@ foreignObject = $foreignObject; + $this->remoteField = $remoteField; + $this->localElement = $localElement; + } + + /** + * Get the data of the relation + */ + function get() + { + return $this->foreignObject::findMany(array($this->remoteField => array('=', $this->localElement->id))); + } + +} diff --git a/src/ORM/Relations/HasOne.php b/src/ORM/Relations/HasOne.php new file mode 100644 index 0000000..484d751 --- /dev/null +++ b/src/ORM/Relations/HasOne.php @@ -0,0 +1,35 @@ +foreignObject = $foreignObject; + $this->remoteField = $remoteField; + $this->localElement = $localElement; + } + + function get() + { + return $this->foreignObject::findOne(array($this->remoteField => array('=', $this->localElement->id))); + } + +}