<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def detach(self, ids=None, touch=True):
 """ Detach models from the relationship. """

        if isinstance(ids, orator.orm.model.Model):
            ids = ids.get_key()

        if ids is None:
            ids = []

        query = self._new_pivot_query()

        if not isinstance(ids, list):
            ids = [ids]

        if len(ids) > 0:
            query.where_in(self._other_key, ids)

        if touch:
            self.touch_if_touching()

        results = query.delete()

        return results