mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-06-04 23:06:24 -04:00
- Fixed bug regarding "subqueryload" strategy whereby
strategy would fail if the entity was an aliased() construct. [ticket:1964]
This commit is contained in:
@@ -20,6 +20,10 @@ CHANGES
|
||||
a referenced child row to be correctly returned
|
||||
in results. [ticket:1954]
|
||||
|
||||
- Fixed bug regarding "subqueryload" strategy whereby
|
||||
strategy would fail if the entity was an aliased()
|
||||
construct. [ticket:1964]
|
||||
|
||||
- engine
|
||||
- Implemented sequence check capability for the C
|
||||
version of RowProxy, as well as 2.7 style
|
||||
|
||||
@@ -740,14 +740,16 @@ class SubqueryLoader(AbstractRelationshipLoader):
|
||||
("orig_query", SubqueryLoader),
|
||||
context.query)
|
||||
|
||||
subq_mapper = mapperutil._class_to_mapper(subq_path[0])
|
||||
|
||||
# determine attributes of the leftmost mapper
|
||||
if self.parent.isa(subq_path[0]) and self.key==subq_path[1]:
|
||||
if self.parent.isa(subq_mapper) and self.key==subq_path[1]:
|
||||
leftmost_mapper, leftmost_prop = \
|
||||
self.parent, self.parent_property
|
||||
else:
|
||||
leftmost_mapper, leftmost_prop = \
|
||||
subq_path[0], \
|
||||
subq_path[0].get_property(subq_path[1])
|
||||
subq_mapper.get_property(subq_path[1])
|
||||
leftmost_cols, remote_cols = self._local_remote_columns(leftmost_prop)
|
||||
|
||||
leftmost_attr = [
|
||||
|
||||
@@ -42,6 +42,63 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
|
||||
)
|
||||
self.assert_sql_count(testing.db, go, 2)
|
||||
|
||||
@testing.resolve_artifact_names
|
||||
def test_from_aliased(self):
|
||||
mapper(Dingaling, dingalings)
|
||||
mapper(Address, addresses, properties={
|
||||
'dingalings':relationship(Dingaling, order_by=Dingaling.id)
|
||||
})
|
||||
mapper(User, users, properties={
|
||||
'addresses':relationship(
|
||||
Address,
|
||||
order_by=Address.id)
|
||||
})
|
||||
sess = create_session()
|
||||
|
||||
if False:
|
||||
u = aliased(User)
|
||||
q = sess.query(u).options(subqueryload(u.addresses))
|
||||
|
||||
def go():
|
||||
eq_(
|
||||
[User(id=7, addresses=[
|
||||
Address(id=1, email_address='jack@bean.com')])],
|
||||
q.filter(u.id==7).all()
|
||||
)
|
||||
|
||||
self.assert_sql_count(testing.db, go, 2)
|
||||
|
||||
def go():
|
||||
eq_(
|
||||
self.static.user_address_result,
|
||||
q.order_by(u.id).all()
|
||||
)
|
||||
self.assert_sql_count(testing.db, go, 2)
|
||||
|
||||
a = aliased(Address)
|
||||
|
||||
# TODO: this is [ticket:1965]
|
||||
# q = sess.query(User).join((a, User.addresses)).\
|
||||
# options(subqueryload_all(User.addresses, a.dingalings))
|
||||
q = sess.query(User).join((a, User.addresses)).\
|
||||
options(subqueryload_all(User.addresses, Address.dingalings))
|
||||
|
||||
def go():
|
||||
eq_(
|
||||
[
|
||||
User(id=8, addresses=[
|
||||
Address(id=2, email_address='ed@wood.com', dingalings=[Dingaling()]),
|
||||
Address(id=3, email_address='ed@bettyboop.com'),
|
||||
Address(id=4, email_address='ed@lala.com'),
|
||||
]),
|
||||
User(id=9, addresses=[
|
||||
Address(id=5, dingalings=[Dingaling()])
|
||||
]),
|
||||
],
|
||||
q.filter(User.id.in_([8, 9])).all()
|
||||
)
|
||||
self.assert_sql_count(testing.db, go, 3)
|
||||
|
||||
@testing.resolve_artifact_names
|
||||
def test_from_get(self):
|
||||
mapper(User, users, properties={
|
||||
|
||||
Reference in New Issue
Block a user