protected function getKeys(array $entities, $key = null)
    {
        if (is_null($key)) {
            $key = $this->relatedMap->getKeyName();
        }

        $host = $this;

        return array_unique(array_values(array_map(function ($value) use ($key, $host) {
            if (!$value instanceof InternallyMappable) {
                $value = $host->factory->make($value);
            }

            return $value->getEntityAttribute($key);
        }, $entities)));
    }