Martijn Faassen wrote:
>
>
> But I'd like to automate this:
>
> mapper(A, a_table,
>         properties={
>            'bs': my_own_relation(B , backref='a'),
>         })
>
> my_own_relation behaves like relation, except it adds an extra clause
> restricting the query, say, b_table.c.status == 'FOO'. It should have
> access to the parent and child tables so it can do this generically.
>
> I've tried to accomplish this by overriding _determine_joins and
> manipulating self.primaryjoin after the default is set up, but I think
> that breaks because backrefs have already been set up earlier. I've
> hacked around that now I think, but it's not very pretty.

OK well I'm sure you noticed that RelationProperty was not designed to be
subclassed.   I would advise that your my_own_relation() function generate
its own primaryjoin and secondaryjoin conditions which it passes as
arguments to the relation().  If you look at the source of
_determine_joins(), it uses the table.join(othertable).onclause idea, but
more cleanly through a utility function called join_condition().    it
calls it twice to accommodate some more exotic use cases.  I think in
general its fine to call as join_condition(prop.parent, prop.target) which
will give you what you need.



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to