def first_or_new(self, _attributes=None, **attributes):
        if _attributes is not None:
            attributes.update(_attributes)

        instance = self._query.where(attributes).first()
        if instance is None:
            instance = self._related.new_instance()

        return instance
Get the first related model record matching the attributes or instantiate it.
dataset/ETHPy150Open sdispater/orator/orator/orm/relations/belongs_to_many.py/BelongsToMany.first_or_new