本文整理汇总了Python中sqlalchemy.orm.remote方法的典型用法代码示例。如果您正苦于以下问题:Python orm.remote方法的具体用法?Python orm.remote怎么用?Python orm.remote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.orm
的用法示例。
在下文中一共展示了orm.remote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _join_fixture_remote_local_multiple_ref
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _join_fixture_remote_local_multiple_ref(self, **kw):
def fn(a, b):
return (a == b) | (b == a)
return relationships.JoinCondition(
self.selfref,
self.selfref,
self.selfref,
self.selfref,
support_sync=False,
primaryjoin=fn(
# we're putting a do-nothing annotation on
# "a" so that the left/right is preserved;
# annotation vs. non seems to affect __eq__ behavior
self.selfref.c.sid._annotate({"foo": "bar"}),
foreign(remote(self.selfref.c.sid)),
),
)
示例2: test_pj_deannotates
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def test_pj_deannotates(self):
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = "a"
id = Column(Integer, primary_key=True)
class B(Base):
__tablename__ = "b"
id = Column(Integer, primary_key=True)
a_id = Column(ForeignKey(A.id))
a = relationship(A)
eq_(
B.a.property.primaryjoin.left._annotations,
{"parentmapper": A.__mapper__, "remote": True},
)
eq_(
B.a.property.primaryjoin.right._annotations,
{"foreign": True, "local": True, "parentmapper": B.__mapper__},
)
示例3: _descendants_fixture
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _descendants_fixture(self, data=True):
Entity = self.classes.Entity
entity = self.tables.entity
m = mapper(
Entity,
entity,
properties={
"descendants": relationship(
Entity,
primaryjoin=remote(foreign(entity.c.path)).like(
entity.c.path.concat("/%")
),
viewonly=True,
order_by=entity.c.path,
)
},
)
configure_mappers()
assert m.get_property("descendants").direction is ONETOMANY
if data:
return self._fixture()
示例4: setup_classes
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def setup_classes(cls):
Base = cls.DeclarativeBasic
class Venue(Base):
__tablename__ = "venue"
id = Column(Integer, primary_key=True)
name = Column(String)
descendants = relationship(
"Venue",
primaryjoin=func.instr(
remote(foreign(name)), name + "/"
).as_comparison(1, 2)
== 1,
viewonly=True,
order_by=name,
)
示例5: _resolver
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _resolver(cls, prop):
import sqlalchemy
from sqlalchemy.orm import foreign, remote
fallback = sqlalchemy.__dict__.copy()
fallback.update({'foreign': foreign, 'remote': remote})
def resolve_arg(arg):
return _class_resolver(cls, prop, fallback, arg)
return resolve_arg
示例6: setup_listener
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def setup_listener(mapper, class_):
name = class_.__name__
discriminator = name.lower()
class_.addresses = relationship(
Address,
primaryjoin=and_(
class_.id == foreign(remote(Address.parent_id)),
Address.discriminator == discriminator,
),
backref=backref(
"parent_%s" % discriminator,
primaryjoin=remote(class_.id) == foreign(Address.parent_id),
),
)
@event.listens_for(class_.addresses, "append")
def append_address(target, value, initiator):
value.discriminator = discriminator
示例7: _resolver
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _resolver(cls, prop):
import sqlalchemy
from sqlalchemy.orm import foreign, remote
fallback = sqlalchemy.__dict__.copy()
fallback.update({"foreign": foreign, "remote": remote})
def resolve_arg(arg):
return _class_resolver(cls, prop, fallback, arg)
def resolve_name(arg):
return _class_resolver(cls, prop, fallback, arg)._resolve_name
return resolve_name, resolve_arg
示例8: _join_fixture_o2m_composite_selfref_func_annotated
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _join_fixture_o2m_composite_selfref_func_annotated(self, **kw):
return relationships.JoinCondition(
self.composite_selfref,
self.composite_selfref,
self.composite_selfref,
self.composite_selfref,
primaryjoin=and_(
remote(self.composite_selfref.c.group_id)
== func.foo(self.composite_selfref.c.group_id),
remote(self.composite_selfref.c.parent_id)
== self.composite_selfref.c.id,
),
**kw
)
示例9: _join_fixture_compound_expression_1
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _join_fixture_compound_expression_1(self, **kw):
return relationships.JoinCondition(
self.left,
self.right,
self.left,
self.right,
primaryjoin=(self.left.c.x + self.left.c.y)
== relationships.remote(
relationships.foreign(self.right.c.x * self.right.c.y)
),
**kw
)
示例10: _join_fixture_purely_single_o2m
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _join_fixture_purely_single_o2m(self, **kw):
return relationships.JoinCondition(
self.purely_single_col,
self.purely_single_col,
self.purely_single_col,
self.purely_single_col,
support_sync=False,
primaryjoin=self.purely_single_col.c.path.like(
remote(foreign(self.purely_single_col.c.path.concat("%")))
),
)
示例11: _assert_non_simple_warning
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _assert_non_simple_warning(self, fn):
assert_raises_message(
exc.SAWarning,
"Non-simple column elements in "
"primary join condition for property "
r"None - consider using remote\(\) "
"annotations to mark the remote side.",
fn,
)
示例12: _assert_raises_no_local_remote
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def _assert_raises_no_local_remote(self, fn, relname, *arg, **kw):
assert_raises_message(
sa.exc.ArgumentError,
"Relationship %s could not determine "
"any unambiguous local/remote column "
"pairs based on join condition and remote_side arguments. "
r"Consider using the remote\(\) annotation to "
"accurately mark those elements of the join "
"condition that are on the remote side of the relationship."
% (relname),
fn,
*arg,
**kw
)
示例13: test_annotated
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def test_annotated(self):
Employee, Company, employee_t, company_t = (
self.classes.Employee,
self.classes.Company,
self.tables.employee_t,
self.tables.company_t,
)
mapper(Company, company_t)
mapper(
Employee,
employee_t,
properties={
"company": relationship(Company, backref="employees"),
"reports_to": relationship(
Employee,
primaryjoin=sa.and_(
remote(employee_t.c.emp_id)
== employee_t.c.reports_to_id,
remote(employee_t.c.company_id)
== employee_t.c.company_id,
),
backref=backref("employees"),
),
},
)
self._assert_lazy_clauses()
self._test()
示例14: test_overlapping_warning
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def test_overlapping_warning(self):
Employee, Company, employee_t, company_t = (
self.classes.Employee,
self.classes.Company,
self.tables.employee_t,
self.tables.company_t,
)
mapper(Company, company_t)
mapper(
Employee,
employee_t,
properties={
"company": relationship(Company, backref="employees"),
"reports_to": relationship(
Employee,
primaryjoin=sa.and_(
remote(employee_t.c.emp_id)
== employee_t.c.reports_to_id,
remote(employee_t.c.company_id)
== employee_t.c.company_id,
),
backref=backref("employees"),
),
},
)
assert_raises_message(
exc.SAWarning,
r"relationship .* will copy column .* to column "
r"employee_t.company_id, which conflicts with relationship\(s\)",
configure_mappers,
)
示例15: test_annotated_no_overwriting
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import remote [as 别名]
def test_annotated_no_overwriting(self):
Employee, Company, employee_t, company_t = (
self.classes.Employee,
self.classes.Company,
self.tables.employee_t,
self.tables.company_t,
)
mapper(Company, company_t)
mapper(
Employee,
employee_t,
properties={
"company": relationship(Company, backref="employees"),
"reports_to": relationship(
Employee,
primaryjoin=sa.and_(
remote(employee_t.c.emp_id)
== foreign(employee_t.c.reports_to_id),
remote(employee_t.c.company_id)
== employee_t.c.company_id,
),
backref=backref("employees"),
),
},
)
self._assert_lazy_clauses()
self._test_no_warning()