<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _gather_keys_by_type(self, type):
 """ Gather all of the foreign keys for a given type. :param type: The type :type type: str :rtype: BaseCollection """

        foreign = self._foreign_key

        keys = (
            BaseCollection.make(list(self._dictionary[type].values()))
            .map(lambda models: getattr(models[0], foreign))
            .unique()
        )

        return keys