On Aug 22, 2007, at 8:27 AM, Christoph Haas wrote:

>
> But that example deals with User and Address tables and not with
> self-references. I suspect I have to alias the table. Roughly I'm
> thinking of something like:
>
>     properties={
>         'ptr_records': relation(Record, primaryjoin=and_(
>             records_table.c.type=='PTR',  
> records_table.c.inet=records_table2.c.inet
>             ))
>     }
>
> I don't know how to say "match other Record objects where the 'inet'
> column contains the same value". How do I do that correctly?

Well the issue here is that while its a self-referential relationship  
you're dealing with, its not an "adjacency list" model, which is  
really what our "self-referential" relation() is designed to do.   
Normally you can use the "remote_side" attribute to indicate  
whichever column on the join condition is "remote", but here its the  
same column.

Doing the alias thing is possibly a solution.  it would look like this:

records2 = records.alias()

rmapper = mapper(Record, records2, non_primary=True)

'ptr_records':relation(rmapper, primaryjoin=and_(
             records2.c.type=='PTR', records.c.inet=records2.c.inet),
                viewonly=True)
      )

the above should work in theory but I havent tried it.   notice that  
the records2 alias indicates the "child" side of the relationship so  
its the one which gets the "PTR" criterion.  "viewonly=True" is to  
eliminate whatever issues arise in calculating the persistence aspect  
of the relation since you only need loading here.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
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