本文整理汇总了Python中sqlalchemy.orm.relationship方法的典型用法代码示例。如果您正苦于以下问题:Python orm.relationship方法的具体用法?Python orm.relationship怎么用?Python orm.relationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块sqlalchemy.orm的用法示例。
在下文中一共展示了orm.relationship方法的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _memoized_attr_info
点赞 6
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def _memoized_attr_info(self):
"""Info dictionary associated with the object, allowing user-defined
data to be associated with this :class:`.InspectionAttr`.
The dictionary is generated when first accessed. Alternatively,
it can be specified as a constructor argument to the
:func:`.column_property`, :func:`.relationship`, or :func:`.composite`
functions.
.. versionadded:: 0.8 Added support for .info to all
:class:`.MapperProperty` subclasses.
.. versionchanged:: 1.0.0 :attr:`.MapperProperty.info` is also
available on extension types via the
:attr:`.InspectionAttrInfo.info` attribute, so that it can apply
to a wider variety of ORM and extension constructs.
.. seealso::
:attr:`.QueryableAttribute.info`
:attr:`.SchemaItem.info`
"""
return {}
开发者ID:jpush,项目名称:jbox,代码行数:27,
示例2: annotation_association
点赞 6
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def annotation_association(cls):
name = cls.__name__
discriminator = name.lower()
assoc_cls = type(
"%sAnnotationAssociation" % name, (AnnotationAssociation,),
dict(
__tablename__ = None,
__mapper_args__ = {"polymorphic_identity": discriminator},
),
)
cls.annotation = association_proxy(
"annotation_association",
"annotation",
creator = lambda annotation: assoc_cls(annotation = annotation),
)
return relationship(
assoc_cls, backref = backref("parent", uselist = False, collection_class = ordering_list('position'))
)
开发者ID:christoph2,项目名称:pyA2L,代码行数:22,
示例3: ReferenceCol
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def ReferenceCol(tablename, nullable=False, pk_name='id', **kwargs):
"""Column that adds primary key foreign key reference.
Usage: ::
category_id = ReferenceCol('category')
category = relationship('Category', backref='categories')
"""
return db.Column(
db.ForeignKey("{0}.{1}".format(tablename, pk_name)),
nullable=nullable, **kwargs)
开发者ID:codeforamerica,项目名称:comport,代码行数:13,
示例4: __init__
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def __init__(self, private_key=None, wei_target_balance=None, wei_topup_threshold=None):
if private_key:
self.private_key = private_key
else:
self.private_key = Web3.toHex(keccak(os.urandom(4096)))
self.wei_target_balance = wei_target_balance
self.wei_topup_threshold = wei_topup_threshold
# https://stackoverflow.com/questions/20830118/creating-a-self-referencing-m2m-relationship-in-sqlalchemy-flask
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:13,
示例5: to_json
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def to_json(self):
"""Exports the object to a JSON friendly dict
Returns:
Dict representation of object type
"""
output = {
'__type': self.__class__.__name__
}
cls_attribs = self.__class__.__dict__
for attrName in cls_attribs:
attr = getattr(self.__class__, attrName)
value = getattr(self, attrName)
value_class = type(value)
if issubclass(type(attr), QueryableAttribute):
# List of Model, BaseModelMixin objects (one-to-many relationship)
if issubclass(value_class, InstrumentedList):
output[to_camelcase(attrName)] = [x.to_json() for x in value]
# Model, BaseModelMixin object (one-to-one relationship)
elif issubclass(value_class, Model):
output[to_camelcase(attrName)] = value.to_json()
# Datetime object
elif isinstance(value, datetime):
output[to_camelcase(attrName)] = isoformat(value)
elif isinstance(value, enum.Enum):
output[to_camelcase(attrName)] = value.name
# Any primitive type
else:
output[to_camelcase(attrName)] = value
return output
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:39,
示例6: cuser
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def cuser(cls):
return relationship('User', remote_side=User.id,
foreign_keys='{}.cuid'.format(cls.__name__), doc="Created by")
开发者ID:kolypto,项目名称:py-mongosql,代码行数:5,
示例7: roles
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def roles(cls):
return FsModels.db.relationship(
"Role",
secondary=FsModels.roles_users,
backref=FsModels.db.backref("users", lazy="dynamic"),
)
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:8,
示例8: user
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def user(cls):
return relationship("User")
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:4,
示例9: client_id
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def client_id(cls):
return Column(
Integer, ForeignKey("oauth2_client.id", ondelete="CASCADE"), nullable=False
)
# client = relationship("fs_oauth2_client")
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:8,
示例10: transformations
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def transformations(self, relationship="all"):
"""Get all the transformations of this info.
Return a list of transformations involving this info. ``relationship``
can be "parent" (in which case only transformations where the info is
the ``info_in`` are returned), "child" (in which case only
transformations where the info is the ``info_out`` are returned) or
``all`` (in which case any transformations where the info is the
``info_out`` or the ``info_in`` are returned). The default is ``all``
"""
if relationship not in ["all", "parent", "child"]:
raise ValueError(
"You cannot get transformations of relationship {}".format(relationship)
+ "Relationship can only be parent, child or all."
)
if relationship == "all":
return Transformation.query.filter(
and_(
Transformation.failed == false(),
or_(
Transformation.info_in == self, Transformation.info_out == self
),
)
).all()
if relationship == "parent":
return Transformation.query.filter_by(
info_in_id=self.id, failed=False
).all()
if relationship == "child":
return Transformation.query.filter_by(
info_out_id=self.id, failed=False
).all()
开发者ID:Dallinger,项目名称:Dallinger,代码行数:38,
示例11: actual_amount
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def actual_amount(cls):
# see: http://docs.sqlalchemy.org/en/latest/orm/extensions/hybrid.html
# #correlated-subquery-relationship-hybrid
return select(
[func.sum(BudgetTransaction.amount)]
).where(
BudgetTransaction.trans_id.__eq__(cls.id)
).label('actual_amount')
开发者ID:jantman,项目名称:biweeklybudget,代码行数:10,
示例12: reference_col
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def reference_col(tablename, nullable=False, pk_name='id', **kwargs):
"""Column that adds primary key foreign key reference.
Usage: ::
category_id = reference_col('category')
category = relationship('Category', backref='categories')
"""
return db.Column(
db.ForeignKey('{0}.{1}'.format(tablename, pk_name)),
nullable=nullable, **kwargs)
开发者ID:gothinkster,项目名称:flask-realworld-example-app,代码行数:13,
示例13: test_onetomany
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany(metadata):
Table(
"simple_items",
metadata,
Column("id", INTEGER, primary_key=True),
Column("container_id", INTEGER),
ForeignKeyConstraint(["container_id"], ["simple_containers.id"]),
)
Table("simple_containers", metadata, Column("id", INTEGER, primary_key=True))
assert (
generate_code(metadata)
== """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class SimpleContainer(Base):
__tablename__ = 'simple_containers'
id = Column(Integer, primary_key=True)
class SimpleItem(Base):
__tablename__ = 'simple_items'
id = Column(Integer, primary_key=True)
container_id = Column(ForeignKey('simple_containers.id'))
container = relationship('SimpleContainer')
"""
)
开发者ID:thomaxxl,项目名称:safrs,代码行数:39,
示例14: test_onetomany_selfref
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany_selfref(metadata):
Table(
"simple_items",
metadata,
Column("id", INTEGER, primary_key=True),
Column("parent_item_id", INTEGER),
ForeignKeyConstraint(["parent_item_id"], ["simple_items.id"]),
)
assert (
generate_code(metadata)
== """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class SimpleItem(Base):
__tablename__ = 'simple_items'
id = Column(Integer, primary_key=True)
parent_item_id = Column(ForeignKey('simple_items.id'))
parent_item = relationship('SimpleItem', remote_side=[id])
"""
)
开发者ID:thomaxxl,项目名称:safrs,代码行数:32,
示例15: test_onetomany_selfref_multi
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany_selfref_multi(metadata):
Table(
"simple_items",
metadata,
Column("id", INTEGER, primary_key=True),
Column("parent_item_id", INTEGER),
Column("top_item_id", INTEGER),
ForeignKeyConstraint(["parent_item_id"], ["simple_items.id"]),
ForeignKeyConstraint(["top_item_id"], ["simple_items.id"]),
)
assert (
generate_code(metadata)
== """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class SimpleItem(Base):
__tablename__ = 'simple_items'
id = Column(Integer, primary_key=True)
parent_item_id = Column(ForeignKey('simple_items.id'))
top_item_id = Column(ForeignKey('simple_items.id'))
parent_item = relationship('SimpleItem', remote_side=[id], \
primaryjoin='SimpleItem.parent_item_id == SimpleItem.id')
top_item = relationship('SimpleItem', remote_side=[id], \
primaryjoin='SimpleItem.top_item_id == SimpleItem.id')
"""
)
开发者ID:thomaxxl,项目名称:safrs,代码行数:38,
示例16: test_onetomany_noinflect
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany_noinflect(metadata):
Table(
"oglkrogk",
metadata,
Column("id", INTEGER, primary_key=True),
Column("fehwiuhfiwID", INTEGER),
ForeignKeyConstraint(["fehwiuhfiwID"], ["fehwiuhfiw.id"]),
)
Table("fehwiuhfiw", metadata, Column("id", INTEGER, primary_key=True))
assert (
generate_code(metadata)
== """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class Fehwiuhfiw(Base):
__tablename__ = 'fehwiuhfiw'
id = Column(Integer, primary_key=True)
class Oglkrogk(Base):
__tablename__ = 'oglkrogk'
id = Column(Integer, primary_key=True)
fehwiuhfiwID = Column(ForeignKey('fehwiuhfiw.id'))
fehwiuhfiw = relationship('Fehwiuhfiw')
"""
)
开发者ID:thomaxxl,项目名称:safrs,代码行数:39,
示例17: test_foreign_key_schema
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_foreign_key_schema(metadata):
Table(
"simple_items",
metadata,
Column("id", INTEGER, primary_key=True),
Column("other_item_id", INTEGER),
ForeignKeyConstraint(["other_item_id"], ["otherschema.other_items.id"]),
)
Table("other_items", metadata, Column("id", INTEGER, primary_key=True), schema="otherschema")
assert (
generate_code(metadata)
== """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class OtherItem(Base):
__tablename__ = 'other_items'
__table_args__ = {'schema': 'otherschema'}
id = Column(Integer, primary_key=True)
class SimpleItem(Base):
__tablename__ = 'simple_items'
id = Column(Integer, primary_key=True)
other_item_id = Column(ForeignKey('otherschema.other_items.id'))
other_item = relationship('OtherItem')
"""
)
开发者ID:thomaxxl,项目名称:safrs,代码行数:40,
示例18: parent
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def parent(self):
return relationship(
self,
order_by=lambda: self.left,
foreign_keys=[self.parent_id],
remote_side="{}.{}".format(self.__name__, self.get_pk_name()),
backref=backref(
"children",
cascade="all,delete",
order_by=lambda: (self.tree_id, self.left),
),
)
开发者ID:uralbash,项目名称:sqlalchemy_mptt,代码行数:14,
示例19: reference_col
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def reference_col(tablename: str, nullable: bool = False, pk_name: str = 'id',
onupdate: str = None, ondelete: str = None, **kwargs: Any) \
-> Column:
"""Column that adds primary key foreign key reference.
Args:
tablename (str): Model.__table_name__.
nullable (bool): Default is False.
pk_name (str): Primary column's name.
onupdate (str): If Set, emit ON UPDATE when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.
ondelete (str): If set, emit ON DELETE when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.
Others:
See ``sqlalchemy.Column``.
Examples::
from sqlalchemy.orm import relationship
role_id = reference_col('role')
role = relationship('Role', backref='users', cascade='all, delete')
"""
return Column(
ForeignKey('{0}.{1}'.format(tablename, pk_name),
onupdate=onupdate, ondelete=ondelete),
nullable=nullable, **kwargs)
开发者ID:TTWShell,项目名称:hobbit-core,代码行数:34,代码来源:db.py
示例20: home_team
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def home_team(cls):
return relationship('Clubs', foreign_keys="{}.home_team_id".format(cls.__name__),
backref=backref('home_friendly_matches'))
开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,
示例21: away_team
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def away_team(cls):
return relationship('Clubs', foreign_keys="{}.away_team_id".format(cls.__name__),
backref=backref('away_friendly_matches'))
开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,
示例22: home_team
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def home_team(cls):
return relationship('Countries', foreign_keys="{}.home_team_id".format(cls.__name__),
backref=backref('home_friendly_matches'))
开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,
示例23: away_team
点赞 5
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def away_team(cls):
return relationship('Countries', foreign_keys="{}.away_team_id".format(cls.__name__),
backref=backref('away_friendly_matches'))
开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,
注:本文中的sqlalchemy.orm.relationship方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。