I guess I should restate the question.
I have two tables:
class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
mdata = Column(UnicodeText)
bar = relation("Bar")
def __repr__(self):
return "Foo(%r)" % self.mdata
class Bar(Base):
__tablename__ = 'bar'
id = Column(Integer, primary_key=True)
mdata = Column(UnicodeText)
username = Column(UnicodeText)
foo_id = Column(Integer,
ForeignKey('
foo.id'))
def __repr__(self):
return "Bar(%r)" % self.mdata
Foo contains records:
mysql> select * from foo;
+----+-------+
| id | mdata |
+----+-------+
| 1 | f1 |
| 2 | f2 |
| 3 | f3 |
| 4 | f4 |
| 5 | f5 |
+----+-------+
5 rows in set (0.00 sec)
Bar contains records:
mysql> select * from bar;
+----+-------+----------+--------+
| id | mdata | username | foo_id |
+----+-------+----------+--------+
| 1 | b1 | hal | 1 |
| 2 | b2 | hal | 2 |
| 3 | b3 | homer | 2 |
+----+-------+----------+--------+
3 rows in set (0.00 sec)
Note there are at most 1 Bar record for a given Foo record,
for a given username (but there could be none).
Given a particular username, I would like to select a range
of Foo records (offset,limit), outer-joined with Bar
records (for that username), and ordered by, say Foo.mdata
(ordered *before* the range).
For example, say I am looking at username = u'hal'. I would
like to construct an efficient query q such that:
q[0:3] gives me something like:
[(Foo(u'f1'), Bar(u'b1')),
(Foo(u'f2'), Bar(u'b2')),
(Foo(u'f3'), None)]
I have tried constructs similar to the ones in my original
question, but so far nothing has worked quite right.
Thank you for your time, and please, forgive my ignorance, but
I am very confused!
David