<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_relation(self, name, klass=None):
 """ Constructs a related ``Resource`` or ``Collection``. This allows for construction of classes with information prepopulated from what the current instance has. This enables syntax like:: bucket = Bucket(bucket='some-bucket-name') for obj in bucket.objects.each():
 print(obj.key) :param name: The name of the relation from the ResourceJSON :type name: string :param klass: (Optional) An overridable class to construct. Typically only useful if you need a custom subclass used in place of what kotocore provides. :type klass: class :returns: An instantiated related object """

        try:
            rel_data = self._details.relations[name]
        except KeyError:
            msg = "No such relation named '{0}'.".format(name)
            raise NoRelation(msg)

        if klass is None:
            # This is the typical case, where we're not explicitly given a
            # class to build with. Hit the session & look up what we should
            # be loading.
            if rel_data['class_type'] == 'collection':
                klass = self._details.session.get_collection(
                    self._details.service_name,
                    rel_data['class']
                )
            elif rel_data['class_type'] == 'resource':
                klass = self._details.session.get_resource(
                    self._details.service_name,
                    rel_data['class']
                )
            else:
                msg = "Unknown class '{0}' for '{1}'.".format(
                    rel_data['class_type'],
                    name
                )
                raise NoRelation(msg)

        # Instantiate & return it.
        kwargs = {}
        # Just populating identifiers is enough for the 1-M case.
        kwargs.update(self.get_identifiers())

        if rel_data.get('rel_type', '1-M') == '1-1':
            # FIXME: If it's not a collection, we might have some instance data
            #        (i.e. ``bucket``) in ``self._data`` to populate as well.
            #        This seems like a can of worms, so ignore for the moment.
            pass

        return klass(connection=self._connection, **kwargs)