Moving the relations to a dedicated Namespace
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user