def METHOD_NAME(cls, identity, link_type, media_item):
    obj = (cls.query
           .filter(cls.link_type == link_type)
           .filter(getattr(cls, cls._identity) == identity)
           .first())
    if obj is None:
        obj = cls(link_type=link_type)
        setattr(obj, cls._identity, identity)
        cls.dbsession.add(obj)
    obj.media_item = media_item
    cls.refresh_cache(identity)