|
@@ -11,8 +11,9 @@ class BelongsToManyExtended {
|
|
|
private $remoteInPivot;
|
|
private $remoteInPivot;
|
|
|
private $remoteFilter;
|
|
private $remoteFilter;
|
|
|
private $remoteLimit;
|
|
private $remoteLimit;
|
|
|
|
|
+ private $softDelete;
|
|
|
|
|
|
|
|
- function __construct($localObject, $foreignObject, $pivotTable, $localInPivot, $remoteInPivot, $remoteFilter = Array(), $remoteLimit = Array()) {
|
|
|
|
|
|
|
+ function __construct($localObject, $foreignObject, $pivotTable, $localInPivot, $remoteInPivot, $remoteFilter = Array(), $remoteLimit = Array(), $softDelete) {
|
|
|
$this->localObject = $localObject;
|
|
$this->localObject = $localObject;
|
|
|
$this->foreignObject = $foreignObject;
|
|
$this->foreignObject = $foreignObject;
|
|
|
$this->pivotTable = $pivotTable;
|
|
$this->pivotTable = $pivotTable;
|
|
@@ -20,33 +21,42 @@ class BelongsToManyExtended {
|
|
|
$this->remoteInPivot = $remoteInPivot;
|
|
$this->remoteInPivot = $remoteInPivot;
|
|
|
$this->remoteFilter = $remoteFilter;
|
|
$this->remoteFilter = $remoteFilter;
|
|
|
$this->remoteLimit = $remoteLimit;
|
|
$this->remoteLimit = $remoteLimit;
|
|
|
|
|
+ $this->softDelete = $softDelete;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function get(){
|
|
function get(){
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$limitsSql = '';
|
|
$limitsSql = '';
|
|
|
|
|
+
|
|
|
foreach ($this->remoteLimit as $key => $value) {
|
|
foreach ($this->remoteLimit as $key => $value) {
|
|
|
$limitsSql .= "$key $value ";
|
|
$limitsSql .= "$key $value ";
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- $pivotTable = '{' . $this->pivotTable . '}';
|
|
|
|
|
- $sql = "SELECT * FROM $pivotTable WHERE $this->localInPivot = ? $limitsSql";
|
|
|
|
|
-
|
|
|
|
|
- $relations = DBInstance::query($sql, Array($this->localObject->id), $this->localObject::_connectionName);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $pivotTable = '{' . $this->pivotTable . '}';
|
|
|
|
|
+
|
|
|
|
|
+ $sql = '';
|
|
|
|
|
+ if($this->softDelete){
|
|
|
|
|
+ $sql = "SELECT * FROM $pivotTable WHERE $this->localInPivot = ? AND deleted_at IS NULL $limitsSql";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $sql = "SELECT * FROM $pivotTable WHERE $this->localInPivot = ? $limitsSql";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $relations = DBInstance::query($sql, Array($this->localObject->id), $this->localObject::_connectionName);
|
|
|
$objects = Array();
|
|
$objects = Array();
|
|
|
|
|
|
|
|
if (empty($relations)) {
|
|
if (empty($relations)) {
|
|
|
return Array();
|
|
return Array();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
foreach ($relations as $relation) {
|
|
foreach ($relations as $relation) {
|
|
|
$relation->childElement = $this->foreignObject::findOne(array_merge(Array("id" => Array("=", $relation->{$this->remoteInPivot})), $this->remoteFilter));
|
|
$relation->childElement = $this->foreignObject::findOne(array_merge(Array("id" => Array("=", $relation->{$this->remoteInPivot})), $this->remoteFilter));
|
|
|
$objects[] = $relation;
|
|
$objects[] = $relation;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (empty($objects)) {
|
|
if (empty($objects)) {
|
|
|
return Array();
|
|
return Array();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return $objects;
|
|
return $objects;
|
|
|
}
|
|
}
|
|
|
|
|
|