Here are the examples of the python api sqlalchemy.orm.relationship taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : test_lazy_relations.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_dont_use_get_pj_is_different(self):
mapper(self.clastes.A, self.tables.a)
m_b = mapper(
self.clastes.B,
self.tables.b_sameorder,
properties={
"a": relationship(
self.clastes.A,
primaryjoin=and_(
self.tables.a.c.id1 == self.tables.b_sameorder.c.a_id1,
self.tables.a.c.id2 == 12,
),
)
},
)
configure_mappers()
is_false(m_b.relationships.a.strategy.use_get)
3
View Complete Implementation : test_reflection.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_table_resolution(self):
clast User(decl.DeferredReflection, fixtures.ComparableEnsaty, Base):
__tablename__ = "users"
items = relationship(
"Item", secondary=Table("user_items", Base.metadata)
)
clast Item(decl.DeferredReflection, fixtures.ComparableEnsaty, Base):
__tablename__ = "items"
decl.DeferredReflection.prepare(testing.db)
self._roundtrip()
3
View Complete Implementation : test_orm.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
@clastmethod
def setup_mappers(cls):
Child, Parent, parent, child = (
cls.clastes.Child,
cls.clastes.Parent,
cls.tables.parent,
cls.tables.child,
)
mapper(
Parent,
parent,
properties={"children": relationship(Child, backref="parent")},
)
mapper(Child, child)
3
View Complete Implementation : test_baked.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def _o2m_fixture(self, lazy="select", **kw):
User = self.clastes.User
Address = self.clastes.Address
mapper(
User,
self.tables.users,
properties={
"addresses": relationship(
Address,
order_by=self.tables.addresses.c.id,
lazy=lazy,
**kw
)
},
)
mapper(Address, self.tables.addresses)
return User, Address
3
View Complete Implementation : test_baked.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def _m2o_fixture(self):
User = self.clastes.User
Address = self.clastes.Address
mapper(User, self.tables.users)
mapper(
Address,
self.tables.addresses,
properties={"user": relationship(User)},
)
return User, Address
3
View Complete Implementation : test_reflection.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_exception_prepare_not_called(self):
clast User(decl.DeferredReflection, fixtures.ComparableEnsaty, Base):
__tablename__ = "users"
addresses = relationship("Address", backref="user")
clast Address(
decl.DeferredReflection, fixtures.ComparableEnsaty, Base
):
__tablename__ = "addresses"
astert_raises_message(
orm_exc.UnmappedClastError,
"Clast test.ext.declarative.test_reflection.User is a "
"subclast of DeferredReflection. Mappings are not produced "
r"until the .prepare\(\) method is called on the clast "
"hierarchy.",
Session().query,
User,
)
3
View Complete Implementation : test_update_delete.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
@clastmethod
def setup_mappers(cls):
User = cls.clastes.User
users = cls.tables.users
Address = cls.clastes.Address
addresses = cls.tables.addresses
mapper(
User,
users,
properties={
"age": users.c.age_int,
"addresses": relationship(Address),
},
)
mapper(Address, addresses)
3
View Complete Implementation : test_reflection.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_string_resolution(self):
clast User(decl.DeferredReflection, fixtures.ComparableEnsaty, Base):
__tablename__ = "users"
items = relationship("Item", secondary="user_items")
clast Item(decl.DeferredReflection, fixtures.ComparableEnsaty, Base):
__tablename__ = "items"
decl.DeferredReflection.prepare(testing.db)
self._roundtrip()
3
View Complete Implementation : test_automap.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_relationship_explicit_override_m2o(self):
Base = automap_base(metadata=self.metadata)
prop = relationship("users")
clast Address(Base):
__tablename__ = "addresses"
users = prop
Base.prepare()
User = Base.clastes.users
astert Address.users.property is prop
a1 = Address(email_address="e1")
u1 = User(name="u1", address_collection=[a1])
astert a1.users is u1
3
View Complete Implementation : test_orm.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
@clastmethod
def setup_mappers(cls):
Child, Parent, parent, child = (
cls.clastes.Child,
cls.clastes.Parent,
cls.tables.parent,
cls.tables.child,
)
mapper(
Parent,
parent,
properties={"children": relationship(Child, backref="parent")},
)
mapper(Child, child)