Moving the relations to a dedicated Namespace
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ORM;
|
||||
|
||||
class HasMany {
|
||||
|
||||
private $foreignObject;
|
||||
private $remoteField;
|
||||
private $localElement;
|
||||
|
||||
function __construct($foreignObject, $remoteField, $localElement) {
|
||||
$this->foreignObject = $foreignObject;
|
||||
$this->remoteField = $remoteField;
|
||||
$this->localElement = $localElement;
|
||||
}
|
||||
|
||||
function get() {
|
||||
return $this->foreignObject::findMany(Array($this->remoteField => Array('=', $this->localElement->id)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ORM
|
||||
;
|
||||
|
||||
class HasOne{
|
||||
|
||||
private $foreignObject;
|
||||
private $remoteField;
|
||||
private $localElement;
|
||||
|
||||
function __construct($foreignObject, $remoteField, $localElement) {
|
||||
$this->foreignObject = $foreignObject;
|
||||
$this->remoteField = $remoteField;
|
||||
$this->localElement = $localElement;
|
||||
}
|
||||
|
||||
function get(){
|
||||
return $this->foreignObject::findOne(Array($this->remoteField => Array('=', $this->localElement->id)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace ORM;
|
||||
namespace ORM\Relations;
|
||||
|
||||
/**
|
||||
* BelongsTo
|
||||
*
|
||||
* Defines that, this object is part of an other class.
|
||||
* The local field must match the id of an other class.
|
||||
*
|
||||
* Table Post = (id, name, content)
|
||||
* Table Comment = (id, name, content, postid)
|
||||
*
|
||||
* This relation will be created on the comment class
|
||||
* Making reference to the post class
|
||||
*/
|
||||
class BelongsTo {
|
||||
|
||||
private $foreignObject;
|
||||
@@ -1,7 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace ORM;
|
||||
namespace ORM\Relations;
|
||||
|
||||
use ORM\DBInstance;
|
||||
use ORM\Collection;
|
||||
|
||||
/**
|
||||
* Belongs to Many
|
||||
*
|
||||
* Defines that this object is related to many other instances
|
||||
* of other classes throw a pivot table.
|
||||
*
|
||||
* Table Post = (id, name, content)
|
||||
* Table Tag = (id, name)
|
||||
* Table Post_Tag = (id, postid, tagid)
|
||||
*
|
||||
* This relation will be created in both classes
|
||||
*/
|
||||
class BelongsToMany {
|
||||
|
||||
private $localObject;
|
||||
@@ -12,6 +27,17 @@ class BelongsToMany {
|
||||
private $remoteFilter;
|
||||
private $remoteLimit;
|
||||
|
||||
/**
|
||||
* Build the Connection
|
||||
*
|
||||
* @param mixed $localObject
|
||||
* @param mixed $foreignObject
|
||||
* @param mixed $pivotTable
|
||||
* @param mixed $localInPivot
|
||||
* @param mixed $remoteInPivot
|
||||
* @param mixed $remoteFilter
|
||||
* @param mixed $remoteLimit
|
||||
*/
|
||||
function __construct($localObject, $foreignObject, $pivotTable, $localInPivot, $remoteInPivot, $remoteFilter = Array(), $remoteLimit = Array()) {
|
||||
$this->localObject = $localObject;
|
||||
$this->foreignObject = $foreignObject;
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace ORM;
|
||||
namespace ORM\Relations;
|
||||
|
||||
use ORM\DBInstance;
|
||||
use ORM\Collection;
|
||||
|
||||
class BelongsToManyExtended {
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace ORM\Relations;
|
||||
|
||||
/**
|
||||
* Has One
|
||||
*
|
||||
* Defines that, this object has a child only one object in other class.
|
||||
*
|
||||
* Table user = (id, name)
|
||||
* Table phone = (id, number, userid)
|
||||
*
|
||||
* This relation will be created on the User class
|
||||
* making reference to the Phone class
|
||||
*/
|
||||
class HasOne
|
||||
{
|
||||
|
||||
private $foreignObject;
|
||||
private $remoteField;
|
||||
private $localElement;
|
||||
|
||||
function __construct($foreignObject, $remoteField, $localElement)
|
||||
{
|
||||
$this->foreignObject = $foreignObject;
|
||||
$this->remoteField = $remoteField;
|
||||
$this->localElement = $localElement;
|
||||
}
|
||||
|
||||
function get()
|
||||
{
|
||||
return $this->foreignObject::findOne(array($this->remoteField => array('=', $this->localElement->id)));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user