Files
orm/src/ORM/Relations/HasMany.php
T

46 lines
1016 B
PHP

<?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)));
}
}