Python sqlalchemy.orm.remote() Examples
The following are 23
code examples of sqlalchemy.orm.remote().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.orm
, or try the search function
.
Example #1
Source File: test_relationships.py From sqlalchemy with MIT License | 6 votes |
def setup_classes(cls): Base = cls.DeclarativeBasic class Network(fixtures.ComparableEntity, Base): __tablename__ = "network" id = Column( sa.Integer, primary_key=True, test_needs_autoincrement=True ) ip_net_addr = Column(Integer) ip_broadcast_addr = Column(Integer) addresses = relationship( "Address", primaryjoin="remote(foreign(Address.ip_addr)).between(" "Network.ip_net_addr," "Network.ip_broadcast_addr)", viewonly=True, ) class Address(fixtures.ComparableEntity, Base): __tablename__ = "address" ip_addr = Column(Integer, primary_key=True)
Example #2
Source File: test_relationships.py From sqlalchemy with MIT License | 6 votes |
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, )
Example #3
Source File: test_relationships.py From sqlalchemy with MIT License | 6 votes |
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()
Example #4
Source File: test_rel_fn.py From sqlalchemy with MIT License | 6 votes |
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)), ), )
Example #5
Source File: test_rel_fn.py From sqlalchemy with MIT License | 6 votes |
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__}, )
Example #6
Source File: test_rel_fn.py From sqlalchemy with MIT License | 5 votes |
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, )
Example #7
Source File: clsregistry.py From android_universal with MIT License | 5 votes |
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
Example #8
Source File: clsregistry.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: clsregistry.py From jarvis with GNU General Public License v2.0 | 5 votes |
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
Example #10
Source File: test_relationships.py From sqlalchemy with MIT License | 5 votes |
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()
Example #11
Source File: test_relationships.py From sqlalchemy with MIT License | 5 votes |
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, )
Example #12
Source File: test_relationships.py From sqlalchemy with MIT License | 5 votes |
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()
Example #13
Source File: test_relationships.py From sqlalchemy with MIT License | 5 votes |
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 )
Example #14
Source File: clsregistry.py From jbox with MIT License | 5 votes |
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
Example #15
Source File: test_rel_fn.py From sqlalchemy with MIT License | 5 votes |
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("%"))) ), )
Example #16
Source File: test_rel_fn.py From sqlalchemy with MIT License | 5 votes |
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 )
Example #17
Source File: test_rel_fn.py From sqlalchemy with MIT License | 5 votes |
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 )
Example #18
Source File: clsregistry.py From sqlalchemy with MIT License | 5 votes |
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
Example #19
Source File: generic_fk.py From sqlalchemy with MIT License | 5 votes |
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
Example #20
Source File: clsregistry.py From stdm with GNU General Public License v2.0 | 5 votes |
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
Example #21
Source File: clsregistry.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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
Example #22
Source File: clsregistry.py From planespotter with MIT License | 5 votes |
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
Example #23
Source File: clsregistry.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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