# for the significant columns, not order
# by anything.
q = orig_query._clone()
- q._attributes = {}
- q._attributes[("orig_query", SubqueryLoader)] = orig_query
+# q._attributes = {}
+# q._attributes[("orig_query", SubqueryLoader)] = orig_query
q._set_entities(q._adapt_col_list(leftmost_attr))
if q._limit is None and q._offset is None:
q._order_by = None
-
- q = q.from_self(self.mapper)
+
+ embed_q = q.with_labels().subquery()
+
+ q = q.session.query(self.mapper)
+ q._attributes = {}
+ q._attributes[("orig_query", SubqueryLoader)] = orig_query
+
+ left_alias = mapperutil.AliasedClass(leftmost_mapper, embed_q)
+ q = q.select_from(left_alias)
+
+# q = q.from_self(self.mapper)
# TODO: this is currently a magic hardcody
# flag on _MapperEntity. we should find
# a way to turn it into public functionality.
- q._entities[0]._subq_aliasing = True
+# q._entities[0]._subq_aliasing = True
q._attributes[('subquery_path', None)] = subq_path
]
if len(to_join) < 2:
+# local_attr = [
+# self.parent._get_col_to_prop(c).class_attribute
+# for c in local_cols
+# ]
local_attr = [
- self.parent._get_col_to_prop(c).class_attribute
+ getattr(left_alias, self.parent._get_col_to_prop(c).key)
for c in local_cols
]
else:
else:
q = q.join(prop.class_attribute, aliased=alias_join)
+
# propagate loader options etc. to the new query
q = q._with_current_path(subq_path)
q = q._conditional_options(*orig_query._with_options)
eq_(sess.query(Person).all(), all_employees)
self.assert_sql_count(testing.db, go, {'':14, 'Polymorphic':9}.get(select_type, 10))
+ def test_foo(self):
+ sess = create_session()
+
+ def go():
+ eq_(sess.query(Person).options(subqueryload(Engineer.machines)).all(), all_employees)
+ self.assert_sql_count(testing.db, go, {'':14, 'Unions':8, 'Polymorphic':7}.get(select_type, 8))
+
def test_primary_eager_aliasing(self):
sess = create_session()
eq_(sess.query(Person).options(eagerload(Engineer.machines))[1:3], all_employees[1:3])
self.assert_sql_count(testing.db, go, {'':6, 'Polymorphic':3}.get(select_type, 4))
- # additionally, subqueryload() can't handle from_self() on the union.
- # I'm not too concerned about that.
sess = create_session()
- @testing.fails_if(lambda:select_type == 'Unions')
def go():
eq_(sess.query(Person).options(subqueryload(Engineer.machines)).all(), all_employees)
- self.assert_sql_count(testing.db, go, {'':14, 'Unions':3, 'Polymorphic':7}.get(select_type, 8))
+ self.assert_sql_count(testing.db, go, {'':14, 'Unions':8, 'Polymorphic':7}.get(select_type, 8))
sess = create_session()
self.assert_sql_count(testing.db, go, {'':7, 'Polymorphic':1}.get(select_type, 2))
sess = create_session()
- @testing.fails_if(lambda: select_type=='Unions')
def go():
eq_(
sess.query(Company).options(
)).all(),
assert_result)
- self.assert_sql_count(testing.db, go, {'':9, 'Joins':6,'Unions':3,'Polymorphic':5,'AliasedJoins':6}[select_type])
+ self.assert_sql_count(testing.db, go, {'':9, 'Joins':6,'Unions':6,'Polymorphic':5,'AliasedJoins':6}[select_type])
def test_eagerload_on_subclass(self):
sess = create_session()