diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-10 02:49:12 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-10 02:49:12 +0000 |
commit | b2e04755cc5f382596fb174c7381f60dd2972d94 (patch) | |
tree | bafe994b93bd2a57633c3b9ffedf39d725844350 /test/orm/inheritance5.py | |
parent | 585eacba010eee5be719074fa31d3e8b41cc79a9 (diff) | |
download | sqlalchemy-b2e04755cc5f382596fb174c7381f60dd2972d94.tar.gz |
- the full featureset of the SelectResults extension has been merged
into a new set of methods available off of Query. These methods
all provide "generative" behavior, whereby the Query is copied
and a new one returned with additional criterion added.
The new methods include:
filter() - applies select criterion to the query
filter_by() - applies "by"-style criterion to the query
avg() - return the avg() function on the given column
join() - join to a property (or across a list of properties)
outerjoin() - like join() but uses LEFT OUTER JOIN
limit()/offset() - apply LIMIT/OFFSET
range-based access which applies limit/offset:
session.query(Foo)[3:5]
distinct() - apply DISTINCT
list() - evaluate the criterion and return results
no incompatible changes have been made to Query's API and no methods
have been deprecated. Existing methods like select(), select_by(),
get(), get_by() all execute the query at once and return results
like they always did. join_to()/join_via() are still there although
the generative join()/outerjoin() methods are easier to use.
- the return value for multiple mappers used with instances() now returns
a cartesian product of the requested list of mappers, represented
as a list of tuples. this corresponds to the documented behavior.
So that instances match up properly, the "uniquing" is disabled when
this feature is used.
- strings and columns can also be sent to the *args of instances() where
those exact result columns will be part of the result tuples.
- query() method is added by assignmapper. this helps with
navigating to all the new generative methods on Query.
Diffstat (limited to 'test/orm/inheritance5.py')
-rw-r--r-- | test/orm/inheritance5.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/test/orm/inheritance5.py b/test/orm/inheritance5.py index 640a8d70f..0ae4260dc 100644 --- a/test/orm/inheritance5.py +++ b/test/orm/inheritance5.py @@ -1,6 +1,5 @@ from sqlalchemy import * import testbase -from sqlalchemy.ext.selectresults import SelectResults class AttrSettable(object): def __init__(self, **kwargs): @@ -374,8 +373,8 @@ class RelationTest4(testbase.ORMTest): assert str(car1.employee) == "Engineer E4, status X" session.clear() - s = SelectResults(session.query(Car)) - c = s.join_to("employee").select(employee_join.c.name=="E4")[0] + s = session.query(Car) + c = s.join("employee").select(employee_join.c.name=="E4")[0] assert c.car_id==car1.car_id class RelationTest5(testbase.ORMTest): @@ -580,7 +579,7 @@ class RelationTest7(testbase.ORMTest): for p in r: assert p.car_id == p.car.car_id -class SelectResultsTest(testbase.AssertMixin): +class GenerativeTest(testbase.AssertMixin): def setUpAll(self): # cars---owned by--- people (abstract) --- has a --- status # | ^ ^ | @@ -693,9 +692,9 @@ class SelectResultsTest(testbase.AssertMixin): # test these twice because theres caching involved for x in range(0, 2): - r = SelectResults(session.query(Person)).select_by(people.c.name.like('%2')).join_to('status').select_by(name="active") + r = session.query(Person).filter_by(people.c.name.like('%2')).join('status').filter_by(name="active") assert str(list(r)) == "[Manager M2, category YYYYYYYYY, status Status active, Engineer E2, field X, status Status active]" - r = SelectResults(session.query(Engineer)).join_to('status').select(people.c.name.in_('E2', 'E3', 'E4', 'M4', 'M2', 'M1') & (status.c.name=="active")) + r = session.query(Engineer).join('status').filter(people.c.name.in_('E2', 'E3', 'E4', 'M4', 'M2', 'M1') & (status.c.name=="active")) assert str(list(r)) == "[Engineer E2, field X, status Status active, Engineer E3, field X, status Status active]" class MultiLevelTest(testbase.ORMTest): |