was just attached to object A, *but* object B itself wasnt changed,
the many-to-one synchronize of B's primary key attribute to A's foreign key
attribute wouldnt occur. [ticket:360]
+- implemented from_obj argument for query.count, improves count function
+on selectresults [ticket:325]
0.3.0
- General:
def count(self, whereclause=None, params=None, **kwargs):
"""given a WHERE criterion, create a SELECT COUNT statement, execute and return the resulting count value."""
+
+ from_obj = kwargs.pop('from_obj', [])
+ alltables = []
+ for l in [sql_util.TableFinder(x) for x in from_obj]:
+ alltables += l
+
+ if self.table not in alltables:
+ from_obj.append(self.table)
+
if self._nestable(**kwargs):
- s = self.table.select(whereclause, **kwargs).alias('getcount').count()
+ s = sql.select([self.table], whereclause, **kwargs).alias('getcount').count()
else:
- s = self.table.count(whereclause)
+ s = sql.select([sql.func.count(list(self.table.primary_key)[0])], whereclause, from_obj=from_obj, **kwargs)
return self.session.scalar(self.mapper, s, params=params)
def select_statement(self, statement, **params):
x = query.outerjoin_to('orders').outerjoin_to('items').select(or_(tables.Order.c.order_id==None,tables.Item.c.item_id==2))
print x.compile()
self.assert_result(list(x), tables.User, *tables.user_result[1:3])
+ def test_outerjointo_count(self):
+ """test the join_to and outerjoin_to functions on SelectResults"""
+ mapper(tables.User, tables.users, properties={
+ 'orders':relation(mapper(tables.Order, tables.orders, properties={
+ 'items':relation(mapper(tables.Item, tables.orderitems))
+ }))
+ })
+ session = create_session()
+ query = SelectResults(session.query(tables.User))
+ x = query.outerjoin_to('orders').outerjoin_to('items').select(or_(tables.Order.c.order_id==None,tables.Item.c.item_id==2)).count()
+ assert x==2
def test_from(self):
mapper(tables.User, tables.users, properties={
'orders':relation(mapper(tables.Order, tables.orders, properties={