Moving the relations to a dedicated Namespace

This commit is contained in:
2026-08-19 10:59:49 -03:00
parent 64bce1da47
commit 46dd177be9
7 changed files with 124 additions and 46 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace ORM\Relations;
/**
* HasMany
*
* Defines that, this object has many instances of other Object
*
* Table Post = (id, name, content)
* Table Comment = (id, name, content, postid)
*
* This relation will be created on the Post class
* Making reference to the Comment class
*/
class HasMany
{
private $foreignObject;
private $remoteField;
private $localElement;
/**
* Return the Relation
*
* @param mixed $foreignObject
* @param mixed $remoteField
* @param mixed $localElement
*/
function __construct($foreignObject, $remoteField, $localElement)
{
$this->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)));
}
}