当前位置: 首页>>代码示例>>Python>>正文


Python automap.generate_relationship方法代码示例

本文整理汇总了Python中sqlalchemy.ext.automap.generate_relationship方法的典型用法代码示例。如果您正苦于以下问题:Python automap.generate_relationship方法的具体用法?Python automap.generate_relationship怎么用?Python automap.generate_relationship使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.ext.automap的用法示例。


在下文中一共展示了automap.generate_relationship方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_relationship_pass_params

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def test_relationship_pass_params(self):
        Base = automap_base(metadata=self.metadata)

        mock = Mock()

        def _gen_relationship(
            base, direction, return_fn, attrname, local_cls, referred_cls, **kw
        ):
            mock(base, direction, attrname)
            return generate_relationship(
                base,
                direction,
                return_fn,
                attrname,
                local_cls,
                referred_cls,
                **kw
            )

        Base.prepare(generate_relationship=_gen_relationship)
        assert set(tuple(c[1]) for c in mock.mock_calls).issuperset(
            [
                (Base, interfaces.MANYTOONE, "nodes"),
                (Base, interfaces.MANYTOMANY, "keywords_collection"),
                (Base, interfaces.MANYTOMANY, "items_collection"),
                (Base, interfaces.MANYTOONE, "users"),
                (Base, interfaces.ONETOMANY, "addresses_collection"),
            ]
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:31,代码来源:test_automap.py

示例2: test_conditional_relationship

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def test_conditional_relationship(self):
        Base = automap_base()

        def _gen_relationship(*arg, **kw):
            return None

        Base.prepare(
            engine=testing.db,
            reflect=True,
            generate_relationship=_gen_relationship,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:13,代码来源:test_automap.py

示例3: generate_relationship

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def generate_relationship(
        base, direction, return_fn, attrname, local_cls, referred_cls, **kw):
    """Generate a :func:`.relationship` or :func:`.backref` on behalf of two
    mapped classes.

    An alternate implementation of this function can be specified using the
    :paramref:`.AutomapBase.prepare.generate_relationship` parameter.

    The default implementation of this function is as follows::

        if return_fn is backref:
            return return_fn(attrname, **kw)
        elif return_fn is relationship:
            return return_fn(referred_cls, **kw)
        else:
            raise TypeError("Unknown relationship function: %s" % return_fn)

    :param base: the :class:`.AutomapBase` class doing the prepare.

    :param direction: indicate the "direction" of the relationship; this will
     be one of :data:`.ONETOMANY`, :data:`.MANYTOONE`, :data:`.MANYTOMANY`.

    :param return_fn: the function that is used by default to create the
     relationship.  This will be either :func:`.relationship` or
     :func:`.backref`.  The :func:`.backref` function's result will be used to
     produce a new :func:`.relationship` in a second step, so it is critical
     that user-defined implementations correctly differentiate between the two
     functions, if a custom relationship function is being used.

    :attrname: the attribute name to which this relationship is being assigned.
     If the value of :paramref:`.generate_relationship.return_fn` is the
     :func:`.backref` function, then this name is the name that is being
     assigned to the backref.

    :param local_cls: the "local" class to which this relationship or backref
     will be locally present.

    :param referred_cls: the "referred" class to which the relationship or
     backref refers to.

    :param \**kw: all additional keyword arguments are passed along to the
     function.

    :return: a :func:`.relationship` or :func:`.backref` construct, as dictated
     by the :paramref:`.generate_relationship.return_fn` parameter.

    """
    if return_fn is backref:
        return return_fn(attrname, **kw)
    elif return_fn is relationship:
        return return_fn(referred_cls, **kw)
    else:
        raise TypeError("Unknown relationship function: %s" % return_fn) 
开发者ID:jpush,项目名称:jbox,代码行数:55,代码来源:automap.py

示例4: generate_relationship

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def generate_relationship(
        base, direction, return_fn, attrname, local_cls, referred_cls, **kw):
    r"""Generate a :func:`.relationship` or :func:`.backref` on behalf of two
    mapped classes.

    An alternate implementation of this function can be specified using the
    :paramref:`.AutomapBase.prepare.generate_relationship` parameter.

    The default implementation of this function is as follows::

        if return_fn is backref:
            return return_fn(attrname, **kw)
        elif return_fn is relationship:
            return return_fn(referred_cls, **kw)
        else:
            raise TypeError("Unknown relationship function: %s" % return_fn)

    :param base: the :class:`.AutomapBase` class doing the prepare.

    :param direction: indicate the "direction" of the relationship; this will
     be one of :data:`.ONETOMANY`, :data:`.MANYTOONE`, :data:`.MANYTOMANY`.

    :param return_fn: the function that is used by default to create the
     relationship.  This will be either :func:`.relationship` or
     :func:`.backref`.  The :func:`.backref` function's result will be used to
     produce a new :func:`.relationship` in a second step, so it is critical
     that user-defined implementations correctly differentiate between the two
     functions, if a custom relationship function is being used.

    :param attrname: the attribute name to which this relationship is being
     assigned. If the value of :paramref:`.generate_relationship.return_fn` is
     the :func:`.backref` function, then this name is the name that is being
     assigned to the backref.

    :param local_cls: the "local" class to which this relationship or backref
     will be locally present.

    :param referred_cls: the "referred" class to which the relationship or
     backref refers to.

    :param \**kw: all additional keyword arguments are passed along to the
     function.

    :return: a :func:`.relationship` or :func:`.backref` construct, as dictated
     by the :paramref:`.generate_relationship.return_fn` parameter.

    """
    if return_fn is backref:
        return return_fn(attrname, **kw)
    elif return_fn is relationship:
        return return_fn(referred_cls, **kw)
    else:
        raise TypeError("Unknown relationship function: %s" % return_fn) 
开发者ID:yfauser,项目名称:planespotter,代码行数:55,代码来源:automap.py

示例5: generate_relationship

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def generate_relationship(
        base, direction, return_fn, attrname, local_cls, referred_cls, **kw):
    """Generate a :func:`.relationship` or :func:`.backref` on behalf of two
    mapped classes.

    An alternate implementation of this function can be specified using the
    :paramref:`.AutomapBase.prepare.generate_relationship` parameter.

    The default implementation of this function is as follows::

        if return_fn is backref:
            return return_fn(attrname, **kw)
        elif return_fn is relationship:
            return return_fn(referred_cls, **kw)
        else:
            raise TypeError("Unknown relationship function: %s" % return_fn)

    :param base: the :class:`.AutomapBase` class doing the prepare.

    :param direction: indicate the "direction" of the relationship; this will
     be one of :data:`.ONETOMANY`, :data:`.MANYTOONE`, :data:`.MANYTOONE`.

    :param return_fn: the function that is used by default to create the
     relationship.  This will be either :func:`.relationship` or
     :func:`.backref`.  The :func:`.backref` function's result will be used to
     produce a new :func:`.relationship` in a second step, so it is critical
     that user-defined implementations correctly differentiate between the two
     functions, if a custom relationship function is being used.

    :attrname: the attribute name to which this relationship is being assigned.
     If the value of :paramref:`.generate_relationship.return_fn` is the
     :func:`.backref` function, then this name is the name that is being
     assigned to the backref.

    :param local_cls: the "local" class to which this relationship or backref
     will be locally present.

    :param referred_cls: the "referred" class to which the relationship or
     backref refers to.

    :param \**kw: all additional keyword arguments are passed along to the
     function.

    :return: a :func:`.relationship` or :func:`.backref` construct, as dictated
     by the :paramref:`.generate_relationship.return_fn` parameter.

    """
    if return_fn is backref:
        return return_fn(attrname, **kw)
    elif return_fn is relationship:
        return return_fn(referred_cls, **kw)
    else:
        raise TypeError("Unknown relationship function: %s" % return_fn) 
开发者ID:gltn,项目名称:stdm,代码行数:55,代码来源:automap.py

示例6: generate_relationship

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def generate_relationship(
    base, direction, return_fn, attrname, local_cls, referred_cls, **kw
):
    r"""Generate a :func:`_orm.relationship` or :func:`.backref`
    on behalf of two
    mapped classes.

    An alternate implementation of this function can be specified using the
    :paramref:`.AutomapBase.prepare.generate_relationship` parameter.

    The default implementation of this function is as follows::

        if return_fn is backref:
            return return_fn(attrname, **kw)
        elif return_fn is relationship:
            return return_fn(referred_cls, **kw)
        else:
            raise TypeError("Unknown relationship function: %s" % return_fn)

    :param base: the :class:`.AutomapBase` class doing the prepare.

    :param direction: indicate the "direction" of the relationship; this will
     be one of :data:`.ONETOMANY`, :data:`.MANYTOONE`, :data:`.MANYTOMANY`.

    :param return_fn: the function that is used by default to create the
     relationship.  This will be either :func:`_orm.relationship` or
     :func:`.backref`.  The :func:`.backref` function's result will be used to
     produce a new :func:`_orm.relationship` in a second step,
     so it is critical
     that user-defined implementations correctly differentiate between the two
     functions, if a custom relationship function is being used.

    :param attrname: the attribute name to which this relationship is being
     assigned. If the value of :paramref:`.generate_relationship.return_fn` is
     the :func:`.backref` function, then this name is the name that is being
     assigned to the backref.

    :param local_cls: the "local" class to which this relationship or backref
     will be locally present.

    :param referred_cls: the "referred" class to which the relationship or
     backref refers to.

    :param \**kw: all additional keyword arguments are passed along to the
     function.

    :return: a :func:`_orm.relationship` or :func:`.backref` construct,
     as dictated
     by the :paramref:`.generate_relationship.return_fn` parameter.

    """
    if return_fn is backref:
        return return_fn(attrname, **kw)
    elif return_fn is relationship:
        return return_fn(referred_cls, **kw)
    else:
        raise TypeError("Unknown relationship function: %s" % return_fn) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:59,代码来源:automap.py

示例7: generate_relationship

# 需要导入模块: from sqlalchemy.ext import automap [as 别名]
# 或者: from sqlalchemy.ext.automap import generate_relationship [as 别名]
def generate_relationship(base, direction, return_fn, attrname, local_cls, referred_cls, **kw):
    """Generate a :func:`.relationship` or :func:`.backref` on behalf of two
    mapped classes.

    An alternate implementation of this function can be specified using the
    :paramref:`.AutomapBase.prepare.generate_relationship` parameter.

    The default implementation of this function is as follows::

        if return_fn is backref:
            return return_fn(attrname, **kw)
        elif return_fn is relationship:
            return return_fn(referred_cls, **kw)
        else:
            raise TypeError("Unknown relationship function: %s" % return_fn)

    :param base: the :class:`.AutomapBase` class doing the prepare.

    :param direction: indicate the "direction" of the relationship; this will
     be one of :data:`.ONETOMANY`, :data:`.MANYTOONE`, :data:`.MANYTOONE`.

    :param return_fn: the function that is used by default to create the
     relationship.  This will be either :func:`.relationship` or :func:`.backref`.
     The :func:`.backref` function's result will be used to produce a new
     :func:`.relationship` in a second step, so it is critical that user-defined
     implementations correctly differentiate between the two functions, if
     a custom relationship function is being used.

    :attrname: the attribute name to which this relationship is being assigned.
     If the value of :paramref:`.generate_relationship.return_fn` is the
     :func:`.backref` function, then this name is the name that is being
     assigned to the backref.

    :param local_cls: the "local" class to which this relationship or backref
     will be locally present.

    :param referred_cls: the "referred" class to which the relationship or backref
     refers to.

    :param \**kw: all additional keyword arguments are passed along to the
     function.

    :return: a :func:`.relationship` or :func:`.backref` construct, as dictated
     by the :paramref:`.generate_relationship.return_fn` parameter.

    """
    if return_fn is backref:
        return return_fn(attrname, **kw)
    elif return_fn is relationship:
        return return_fn(referred_cls, **kw)
    else:
        raise TypeError("Unknown relationship function: %s" % return_fn) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:54,代码来源:automap.py


注:本文中的sqlalchemy.ext.automap.generate_relationship方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。