I have a simple many to many relationship between two objects: Task and Note, where notes are ordered by a timestamp column most recent first. About 90% of the time what I really want to do is eagerload only the most recent note, is there a way to do this in the mapper?
My mapper for Task looks like this: mapper(Task,task_table, properties={ 'Notes':relation(Note,secondary=note_task_table, order_by=note_table.c.updated.desc(), backref='Tasks'), 'State':relation(TaskState), 'Group':relation(Group, lazy=True)}, save_on_init=False) Usually my code ends up looking like: >>> tasks=session.query(Task).filter(Task.assigned_to=='dgardner').options(eagerload(Task.Notes)).all() >>> for task in tasks: ... if len(task.Notes): ... latest_note=task.Notes[0] -- David Gardner Pipeline Tools Programmer, "Sid the Science Kid" Jim Henson Creature Shop dgard...@creatureshop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---