'Add filtering criterion that relates the given instance
to a child object or collection, using its attribute state
as well as an established :func:`.relationship()`
configuration.
The method uses the :func:`.with_parent` function to generate
the clause, the result of which is passed to :meth:`.Query.filter`.
Parameters are the same as :func:`.with_parent`, with the exception
that the given property can be None, in which case a search is
performed against this :class:`.Query` object\'s target mapper.'

def with_parent(self, instance, property=None):

    if (property is None):
        mapper = object_mapper(instance)
        for prop in mapper.iterate_properties:
            if (isinstance(prop, properties.RelationshipProperty) and (prop.mapper is self._mapper_zero())):
                property = prop
                break
        else:
            raise sa_exc.InvalidRequestError(("Could    not    locate    a    property    which    relates    instances    of    class    '%s'    to    instances    of    class    '%s'" % (self._mapper_zero().class_.__name__, instance.__class__.__name__)))
    return self.filter(with_parent(instance, property))
