Many to many

@param string $target
@param string $through
@param string $key
@param string $target_key
@return array
772138
public function getManyToMany($target, $through, $key = null, $target_key = null){
        $factory = $this->_db->factory($target);

        if(null === $key){
            $key = $this->getPK();
        }
        if(null === $target_key){
            $target_key = $factory->getPK();
        }
        
        $through = $this->parseThrough($through);
        if(!$through[1]){
            $through[1] = $key;
        }
        if(!$through[2]){
            $through[2] = $target_key;
        }
        
        $rows = $this->_db->builder()
            ->select('t.*')
            ->from($factory->getTable().' t')
            ->leftJoin($through[0].' m', 'm.'.$through[2].'=t.'.$target_key)
            ->where('m.'.$through[1].'=:value', array(
                ':value' => $this->get($key)
            ))
        ->queryAll();
        
        if(false === $rows){
            return false;
        }
        
        return $factory->mapModels($rows);
    }
1305686
def relations_to(self, target, include_object=False):
        '''  '''
        if include_object:
            _ = self._execute('''
                select name, (select code from objects where id=src) from relations where dst=?
            ''', (self._id_of(target),))
            for i in _:
                yield self.deserialize(i[1]), i[0]
        else:
            _ = self._execute('''
                select distinct name from relations where dst=?
            ''', (self._id_of(target),))
            for i in _:
                yield i[0]
560773
protected function join($key, $value, $level = 0)
    {
        if ($level > 0) {
            $key = $key . self::LEVEL_SEPARATOR . $level;
        }

        $valueParts = [];
        foreach ($this->unSerializeMap($value) as $mappedKey) {
            $mappedKey = $this->transformReferenceToMappedKey($mappedKey);
            $valueParts[$this->getMappedKeyIndex($mappedKey, $key)] = $this->getDriver()->get($mappedKey);
        }

        uksort($valueParts, 'strnatcmp');
        $value = implode('', $valueParts);
        if ($this->isSplit($value)) {
            $value = $this->join($key, $value, $level + 1);
        }
        return $value;
    }
548815
public function hasManyDeep($related, array $through, array $foreignKeys = [], array $localKeys = [])
    {
        return $this->newHasManyDeep(...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys));
    }
706618
def relations_of(self, target, include_object=False):
        '''  '''
        if include_object:
            _ = self._execute('''
                select relations.name, ob2.code from relations, objects as ob1, objects as ob2 where relations.src=ob1.id and ob2.id=relations.dst and ob1.code=?
            ''', (self.serialize(target),))
            for i in _:
                yield i[0], self.deserialize(i[1])
        else:

            _ = self._execute('''
                select distinct relations.name from relations, objects where relations.src=objects.id and objects.code=?
            ''', (self.serialize(target),))
            for i in _:
                yield i[0]
495965
private function leaveOnlyCurrent(array $row, $target)
    {
        $result = array();

        foreach ($row as $column => $value) {
            if ($column != $target) {
                $result[$column] = $value;
            }
        }

        return $result;
    }
1008348
private function passAsReference (&$target) {
		foreach (Blender::$sharedClasses as $key => $value) {
			if (!property_exists($target,$key) && $value != $target)
				$target->$key = $value;
		}
	}
858285
private function _copySection($source, &$target)
    {
        foreach ($source as $key => $value) {

            if (!array_key_exists($key, $target)) $target[$key] = $value;
        }
    }
1128907
public function getFromPivot (\Sonic\Model $target, \Sonic\Model $pivot, $key = FALSE, $params = [])
	{
		
		// Find the pivot attribute pointing to the source
		
		$sourceClass	= get_called_class ();
		$sourceRef		= FALSE;
		
		foreach ($pivot::$attributes as $name => $attribute)
		{
			if (isset ($attribute['relation']) &&
				$attribute['relation'] == $sourceClass)
			{
				$sourceRef = $name;
				break;
			}
		}
		
		if (!$sourceRef)
		{
			return FALSE;
		}
		
		// Find the pivot attribute pointing to the target
		
		$targetClass	= get_class ($target);
		$targetRef		= FALSE;
		
		foreach ($pivot::$attributes as $name => $attribute)
		{
			if (isset ($attribute['relation']) &&
				$attribute['relation'] == $targetClass)
			{
				$targetRef = $name;
				break;
			}
		}
		
		if (!$targetRef)
		{
			return FALSE;
		}
		
		// Query parameters
		
		if (!isset ($params['select']))
		{
			$params['select']	= 'DISTINCT t.*';
		}
		
		if (isset ($params['from']) && !is_array ($params['from']))
		{
			$params['from']	= [$params['from']];
		}
		
		$params['from'][]	= $target::$dbTable . ' as t';
		$params['from'][]	= $pivot::$dbTable . ' as p';
		
		$params['where'][]	= ['p.' . $sourceRef, $this->getPK ()];
		$params['where'][]	= 'p.' . $targetRef . ' = t.' . $target::$pk;
		
		// Get related objects
		
		return $target::_getObjects ($params, $key);
		
	}
241912
function indexKeys(target, pred) {
  pred = pred || has;
  var results = [];

  for (var i = 0, len = target.length; i < len; i += 1) {
    if (pred(target, i)) {
      results.push(String(i));
    }
  }

  return results;
}
353805
public function target($inverseKey, $references = 'id', $unique = false)
    {
        return $this->inverseKey($inverseKey, $references, $unique);
    }
970020
public function queueIndexingJob(string $target): array
    {
        return $this->getApi()->request(sprintf('/staff/indexing_jobs'), Request::METHOD_POST, [
                'target' => $target
            ]);
    }
395164
private function _mergeAssociated(
        array $result,
        array $associated,
        $refKey,
        $colName
    ) {
        foreach ($result as $index => $item) {

            if (is_array($item)) {
                $refValue = $item[$refKey];
            } else {
                $refValue = $item->{$refKey};
            }

            if (isset($associated[$refValue])) {

                if (is_array($result[$index])) {
                    $result[$index][$colName] = $associated[$refValue];
                } else {
                    $result[$index]->{$colName} = $associated[$refValue];
                }
            }
        }
        return $result;
    }
672142
private function _getLevelAndTargetLoggers( $target )
    {
        $target = strpos($target, ':') !== false ? explode( ':' , $target ) : ['', '*'];
        list($level,$target_loggers) = $target;
        $target_loggers = explode( ',' , $target_loggers );
        $target_loggers = array_map( 'trim', $target_loggers );
        if (in_array('*',$target_loggers))
        {
            $target_loggers = array_keys($this->loggers);
        }
        return array( $level, $target_loggers );
    }
1362696
public function many(array $keys)
    {
        $normalizedKeys = [];

        foreach ($keys as $key => $value) {
            $normalizedKeys[] = is_string($key) ? $key : $value;
        }

        $values = $this->store->many($normalizedKeys);

        foreach ($values as $key => &$value) {
            if (is_null($value) || $value === false) {
                $this->fireCacheEvent('missed', [$key]);

                $value = isset($keys[$key]) ? value($keys[$key]) : null;
            } else {
                $this->fireCacheEvent('hit', [$key, $value]);
            }
        }

        return $values;
    }
651156
public static function findElementsByKey($array, $key, &$targetArray = null, $prefix = "") {

        if ($array instanceof AssociativeArray) {
            $array = $array->toArray();
        }

        if (!$targetArray)
            $targetArray = array();

        foreach ($array as $itemKey => $value) {

            if ($itemKey === $key) {
                $targetArray[substr($prefix . "." . $key, 1)] = $value;
            } else if (is_array($value) || $value instanceof AssociativeArray) {

                if (is_numeric($itemKey)) {
                    $newPrefix = $prefix . "[" . $itemKey . "]";
                } else {
                    $newPrefix = $prefix . "." . $itemKey;
                }

                ArrayUtils::findElementsByKey($value, $key, $targetArray, $newPrefix);
            }
        }

        return $targetArray;

    }
1310400
public function getOneToOne($target, $key = null, $target_key = null){
        $factory = $this->_db->factory($target);
        if(null === $key){
            $key = $this->getPK();
        }
        if(null === $target_key){
            $target_key = $factory->getPK();
        }
        
        return $factory->findOneBy($target_key, $this->get($key));
    }