Hello,
I have two tables defined this way:
tabItems = sqa.Table(meta, "items",
sqa.Column("id", sqa.Integer, primary_key=True),
)
tabTracking = sqa.Table(meta, "tracking",
sqa.Column("id", sqa.Integer, primary_key=True),
sqa.Column("item_id", sqa.Integer, sqa.ForeignKey("items.id")),
sqa.Column("date_start", sqa.DateTime, default="now"),
sqa.Column("date_end", sqa.DateTime, default="infinity"),
)
Now I would like the "Item" mapper to automagically get the last Tracking
record (through MAX() on date_start field)
In SQL should be:
select items.*, tracking.*
from items
left join tracking on
tracking.item_id=items.id
and tracking.date_start = (
select max(date_start)
from tracking t1
where t1.item_id=tracking.item_id
)
Is it possible to write a relation() to perform such a task at mapper level?
--
Cordialmente
Stefano Bartaletti
Responsabile Software
G.Tosi Spa Tintoria
Skype account: stefano.bartaletti
ICQ contact : 1271960
Viale dell'Industria 61
21052 Busto Arsizio (VA)
Tel. +39 0331 34 48 11
Fax +39 0331 35 21 23
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---