Browse Source

Atualizar 'src/BBOrm/Entity.php'

ahwelp 6 years ago
parent
commit
740b889008
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/BBOrm/Entity.php

+ 6 - 2
src/BBOrm/Entity.php

@@ -289,7 +289,11 @@ abstract class Entity {
 
 
     protected function belongs_to_many($foreign_object, $pivot_table, $local_in_pivot, $remote_in_pivot, $remote_filter = Array(), $remote_limit = Array()) {
     protected function belongs_to_many($foreign_object, $pivot_table, $local_in_pivot, $remote_in_pivot, $remote_filter = Array(), $remote_limit = Array()) {
         $obj = new $foreign_object;
         $obj = new $foreign_object;
-
+        $limits_sql = '';
+        
+        foreach ($remote_limit as $key => $value) {
+            $limits_sql .= "$key $value ";
+        }
         $sql = "SELECT $remote_in_pivot FROM $pivot_table WHERE $local_in_pivot = $this->id $limits_sql";
         $sql = "SELECT $remote_in_pivot FROM $pivot_table WHERE $local_in_pivot = $this->id $limits_sql";
 
 
         $relations = DBInstance::query($sql, $this->connection_name);
         $relations = DBInstance::query($sql, $this->connection_name);
@@ -318,7 +322,7 @@ abstract class Entity {
             return Array();
             return Array();
         }
         }
         foreach ($relations as $relation) {
         foreach ($relations as $relation) {
-            $relation->child_element = $obj->find_one(array_merge(Array("id" => Array("=", $relation->$remote_in_pivot), $remote_filter)));
+            $relation->child_element = $obj->find_one(array_merge(Array("id" => Array("=", $relation->$remote_in_pivot)), $remote_filter ));
             $objects[] = $relation;
             $objects[] = $relation;
         }
         }
         if (empty($objects)) {
         if (empty($objects)) {