implement in_() for relations

Issue #1140 new
Former user created an issue

This would have to build upon the "optimized_compare" logic so that a JOIN would not be needed for the primary use case of a many-to-one check for a set of foreign key identifiers.

Comments (5)

  1. Former user Account Deleted

    Is this tough? This feature would make my life a lot better :)

    I can offer a small cash or gift incentive.. A bottle of your favorite tipple, perhaps? sqlalchemy@foo.me.uk if you would like to take it up..

  2. Mike Bayer repo owner

    the basic theory is very simple, at least for many-to-ones, which is probably the only use case I'd want to support. you can do it yourself for simple cases just like:

    query(Parent).filter(Parent.child_id.in_([for c in children](c.id)))
    

    but if the foreign key is composite, then it's a huge PITA unless the backend database supports IN on tuples like PG. So perhaps this would raise for systems that don't support that. Starts getting more tedious.

    if the join condition on the M2O isn't simple, then it gets hard too. So I'd probably only have this operator work if the many-to-one satisfies the "uses get" test - the m2o can be located by primary key alone. this is information the mappers already know so is a simple boolean flag.

    Then you also have all the tests. So with edge cases detected, full tests, documentation, yeah its pretty tedious, half a day usually to make features like these fully polished. The workaround is so simple too.

  3. Log in to comment