On Wednesday, August 15, 2012 11:41:20 AM UTC-4, Michael Bayer wrote:
>
>
>
>
> in this case it seems like you aren't as much concerned about the actual 
> mapper configuration as you are about codepaths being invoked.   So we 
> "instrument" functions to track when they are called. 
>
> You'd make a wrapper around relationship() yourself, which would be used 
> by userland code.  This allows userland relationship() calls to be 
> distinguished from those that SQLAlchemy calls itself internally: 
>
> from sqlalchemy.orm import relationship as _relationship 
> relationships_called = set() 
> def relationship(*arg, **kw): 
>     rel = _relationship(*arg, **kw) 
>     relationships_called.add(rel) 
>     return rel 
>
> def was_relationship_called(rel): 
>     return rel in relationships_called 
>
>
> That's so simple I didn't think of it. I may switch from what I ended up 
doing. I check if the relationship column with the foreign key is on the 
same table as this relationship property. This works because by convention 
I put the relationship on the same table as the FK column and I am working 
on a CRUD that automatically adds relationships to forms only if they can 
be displayed as a simple select list (a relationship that did not have an 
FK on it's model class would need a more advanced interface).

# prop is a RelationshipProperty
for pair in prop.local_remote_pairs:
    for el in pair:
        for fk in el.foreign_keys:
            if fk.parent.table == MyModel.__table__:
                local = True 

Thanks for the help,

Jason

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/5GZlYjt8TQQJ.
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.

Reply via email to