summaryrefslogtreecommitdiff
path: root/test/orm/test_composites.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-10-03 17:06:55 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-10-03 17:06:55 -0400
commita83378b64005971fe97dff270641bce4967dbb53 (patch)
treebbfe8fbf510ddde2c71ff4e26cfe893ca9abce92 /test/orm/test_composites.py
parent78c5249bf7d39c3aaa4954c7815a1ef48f2776db (diff)
downloadsqlalchemy-a83378b64005971fe97dff270641bce4967dbb53.tar.gz
- A new construct :class:`.Bundle` is added, which allows for specification
of groups of column expressions to a :class:`.Query` construct. The group of columns are returned as a single tuple by default. The behavior of :class:`.Bundle` can be overridden however to provide any sort of result processing to the returned row. One example included is :attr:`.Composite.Comparator.bundle`, which applies a bundled form of a "composite" mapped attribute. [ticket:2824] - The :func:`.composite` construct now maintains the return object when used in a column-oriented :class:`.Query`, rather than expanding out into individual columns. This makes use of the new :class:`.Bundle` feature internally. This behavior is backwards incompatible; to select from a composite column which will expand out, use ``MyClass.some_composite.clauses``.
Diffstat (limited to 'test/orm/test_composites.py')
-rw-r--r--test/orm/test_composites.py49
1 files changed, 46 insertions, 3 deletions
diff --git a/test/orm/test_composites.py b/test/orm/test_composites.py
index 5e7b91f3e..eabc9ca7b 100644
--- a/test/orm/test_composites.py
+++ b/test/orm/test_composites.py
@@ -214,17 +214,45 @@ class PointTest(fixtures.MappedTest):
((), [Point(x=None, y=None)], ())
)
- def test_query_cols(self):
+ def test_query_cols_legacy(self):
Edge = self.classes.Edge
sess = self._fixture()
eq_(
- sess.query(Edge.start, Edge.end).all(),
+ sess.query(Edge.start.clauses, Edge.end.clauses).all(),
[(3, 4, 5, 6), (14, 5, 2, 7)]
)
+ def test_query_cols(self):
+ Edge = self.classes.Edge
+ Point = self.classes.Point
+
+ sess = self._fixture()
+
+ start, end = Edge.start, Edge.end
+
+ eq_(
+ sess.query(start, end).filter(start == Point(3, 4)).all(),
+ [(Point(3, 4), Point(5, 6))]
+ )
+
+ def test_query_cols_labeled(self):
+ Edge = self.classes.Edge
+ Point = self.classes.Point
+
+ sess = self._fixture()
+
+ start, end = Edge.start, Edge.end
+
+ row = sess.query(start.label('s1'), end).filter(start == Point(3, 4)).first()
+ eq_(row.s1.x, 3)
+ eq_(row.s1.y, 4)
+ eq_(row.end.x, 5)
+ eq_(row.end.y, 6)
+
def test_delete(self):
+ Point = self.classes.Point
Graph, Edge = self.classes.Graph, self.classes.Edge
sess = self._fixture()
@@ -235,7 +263,10 @@ class PointTest(fixtures.MappedTest):
sess.flush()
eq_(
sess.query(Edge.start, Edge.end).all(),
- [(3, 4, 5, 6), (14, 5, None, None)]
+ [
+ (Point(x=3, y=4), Point(x=5, y=6)),
+ (Point(x=14, y=5), Point(x=None, y=None))
+ ]
)
def test_save_null(self):
@@ -863,3 +894,15 @@ class ComparatorTest(fixtures.MappedTest, testing.AssertsCompiledSQL):
"edge_1.x2, edge_1.y2"
)
+ def test_clause_expansion(self):
+ self._fixture(False)
+ Edge = self.classes.Edge
+ from sqlalchemy.orm import configure_mappers
+ configure_mappers()
+
+ self.assert_compile(
+ select([Edge]).order_by(Edge.start),
+ "SELECT edge.id, edge.x1, edge.y1, edge.x2, edge.y2 FROM edge "
+ "ORDER BY edge.x1, edge.y1"
+ )
+