Lookup a entity based on it's 'primary key' or key column when passed a set.
This will always return a Container
@return Bond\Container
344161
public function findBySet( Set $keySet )
    {

        // the simplest thing that possibly works
        // there're a lot of fairly easy performance gains to doing this differently.
        // this can be speeded up lots. Think interval intersection with value explosion.

        $multiton = $this->makeNewContainer();

        // persisted
        foreach( $this->instancesPersisted as $key => $entity ) {
            if( $keySet->contains( $key ) ) {
                $multiton->add( $entity );
            }
        }

        // unpersisted
        foreach( $this->instancesUnpersisted as $entity ) {
            if( $keySet->contains( $entity->keyGet( $entity ) ) ) {
                $multiton->add( $entity );
            }
        }

        $persisted = parent::findBySet( $keySet );

        return $this->makeNewContainer()->add( $multiton, $persisted );

    }
161873
public function key()
    {
        if (empty($this->key) && !empty($this->definition->primary)) {
            $keys = array_values(
                array_filter(
                    preg_split('~[\s,]+~', $this->definition->primary)
                )
            );
            $keys = array_map(
                function ($key) {
                    return Normalise::toVariable($key);
                },
                $keys
            );

            $this->key = count($keys) > 1 ? $keys : array_shift($keys);
        }

        if (empty($this->key) && $this->has('id')) {
            $this->key = 'id';
        }

        return $this->key;
    }
1322655
protected function _primaryKeyValue()
    {
        $fields = (array)$this->_table()->getPrimaryKey();
        $values = [];
        foreach ($fields as $field) {
            $values[] = $this->_deriveFieldFromContext($field);
        }

        if (count($values) === 1) {
            return $values[0];
        }

        return $values;
    }
351152
public function getPrimaryKeyForForeignModel()
    {
        $model = $this->getForeignModelInstance();

        if ($this->isModel($model)) {
            return $model->getKeyName();
        }

        return $this->getKeyNameFromResource() ?: 'id';
    }
499459
protected function getRelationWhere($links, $key = null) {
        if (is_null($key) && !is_array($links)) {
            $key = in_array('id', $this->primaryKey) ? 'id' : reset($this->primaryKey);
        }
        if (!is_array($links)) {
            $links = [$links => $key];
        }
        foreach ($links as &$item) {
            $item = $this->get($item);
        }
        return $links;
    }
1003700
protected function retrieveByPrimaryKey(array $primary_key_values) {
		/** @var DynamicEntity $entity */
		$entity = parent::retrieveByPrimaryKey($primary_key_values);
		if ($entity) {
			$entity->definition = $this->definition;
		}
		return $entity;
	}
995240
public function find( $primaryKeys )
    {
        if ( is_array( $primaryKeys ) )
        {
            $primaryKeys = reset( $primaryKeys );
        }

        $rootId = ( (int) $primaryKeys ) ?: null;

        return $this->createStructure( array(
            'rootId'    => $rootId,
            'extra'     => $this->getExtraMapper()
                                ->findByRoot( $rootId ),
            'rules'     => $this->getRuleMapper()
                                ->findAllByRoot(
                                    $rootId,
                                    $this->getRuleOrder()
                                ),
        ) );
    }
689552
public function getPrimaryKey()
    {
        if ($this->_primaryKey === null) {
            $key = (array)$this->getSchema()->primaryKey();
            if (count($key) === 1) {
                $key = $key[0];
            }
            $this->_primaryKey = $key;
        }

        return $this->_primaryKey;
    }
405966
public function getParent() {
		$parentid = $this->{$this->parentKeyName};
		if (empty($parentid)) {
			return NULL;
		}
		$collname = $this->collectionName;
		$bitems = $collname::getInstance();
		$fparent = $bitems->itemGet($parentid);
		return $fparent;
	}
698730
public function getForeignKey()
    {
        if (is_null($this->_foreignKey)) {
            $this->setForeignKey($this->_guessForeignKey());
        }
        return $this->_foreignKey;
    }
133249
public function referencedBy( $entity )
    {

        if( !( $entity instanceof Base || $entity instanceof Container ) ) {
            throw new \InvalidArgumentException("You can only lookup references by Entity or Container");
        }

        $class = $entity instanceof Container
            ? $entity->class
            : $entity;

        $properties = $this->propertiesOfTypeGet( $class );

        // found a entity?
        if( !$properties ) {
            throw new \LogicException(
                sprintf(
                    "Can't find which entity property for repository `%s` references entity of type `%s`",
                    $this->entity,
                    $entityClass
                )
            );
        } elseif( count( $properties ) > 1 ) {
            throw new \LogicException(
                sprintf(
                    "Multiple columns [%s] reference a entity of this type [%s]. This is ambiguous. Can't help you here.",
                    implode( ",", $properties ),
                    \Bond\get_unqualified_class( $entity )
                )
            );
        }

        $property = array_pop( $properties );

        // get references to this entity
        $filterComponent = $this->getFindFilterFactory()
            ->get( $property, null, $entity );

        return $this->findByFilterComponents(
            FindFilterComponentFactory::FIND_ALL,
            array( $property => $filterComponent )
        );

    }
379565
public function getPrimaryKey()
    {
        $keys = array();
        $columns = $this->getColumns(true);

        foreach ($columns as $name => $description)
        {
            if ($description->primary) {
                $keys[$name] = $description;
            }
        }

        return $keys;
    }
797611
public function findOne()
    {
        $finder = new DoctrineEntityFinder($this->connection, $this->table, $this->entityClass, $this->entityRegistry);
        $finder->setDispatcher($this->getDispatcher());

        return $finder;
    }
717697
public function getPrimary() {
        foreach ($this->_fields as $key => $field) {
            if ($field->primary == true) {
                $this->_primary = $key;
                break;
            }
        }
    }
1299807
public function lookup($key)
    {
        Arguments::define($this->getKeyType())->check($key);

        if (!$this->member($key)) {
            return Maybe::nothing();
        }

        return Maybe::just($this->value[$key]);
    }
880322
public function getJunction()
    {
        if ($this->relationType == 'hasAndBelongsToMany')
        {
            $tables = $this->tables;
            sort($tables);
            return implode('_', $tables);
        }
        return false;
    }
1104470
protected function _guessForeignKey()
    {
        $descriptor = Entity\Manager::getInstance()
            ->get($this->getRelatedEntity());
        $name = explode('\\', $descriptor->getEntity()->getClassName());
        $name = end($name);
        return strtolower($name) . '_id';
    }