I have a data model which has accounts and events, and a many-to-many relation between the two using a CalendarEvent class. It boils down to this:
class Account(BaseObject): __tablename__ = "account" id = schema.Column("id", types.Integer(), primary_key=True) class Event(BaseObject): __tablename__ = "event" id = schema.Column("id", types.Integer(), primary_key=True) class CalendarEvent(mBaseObject): __tablename__ = "calendar" account_id = schema.Column(types.Integer(), schema.ForeignKey(Account.id, onupdate="CASCADE", ondelete="CASCADE"), primary_key=True, nullable=False) account = orm.relation(Account, backref=orm.backref("calendar", lazy="dynamic")) event_id = schema.Column(types.Integer(), schema.ForeignKey(Event.id, onupdate="CASCADE", ondelete="CASCADE"), primary_key=True, nullable=False) event = orm.relation(Event, lazy=False) the calendar backref works fine when you generate a query for it and generates SQL like this: SELECT calendar.account_id AS calendar_account_id, calendar.event_id AS calendar_event_id, event_1.id AS event_1_id FROM event, calendar LEFT OUTER JOIN event AS event_1 ON event_1.id = calendar.event_id WHERE :param_1 = calendar.account_id but if you use acount.calendar.count() the join conditions disappears and you end up with this: SELECT count(1) AS count_1 FROM calendar, event WHERE %(param_1)s = calendar.account_id which results in an incorrect result. Am I doing something wrong here, or could this be a SQLALchemy bug? If so I can try to boil this down to a failing testcase. Wichert. -- Wichert Akkerman <wich...@wiggy.net> It is simple to make things. http://www.wiggy.net/ It is hard to make things simple. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.