diff --git a/src/BBOrm/Entity.php b/src/BBOrm/Entity.php index a3f1578..8699798 100644 --- a/src/BBOrm/Entity.php +++ b/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()) { $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"; $relations = DBInstance::query($sql, $this->connection_name); @@ -318,7 +322,7 @@ abstract class Entity { return Array(); } 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; } if (empty($objects)) {