a join is of the form:

table1.join(table2, onclause)

such as

subscriber_table.join(address_table,
        and_(address_table.c.subscriber_id==subscriber.c.id,  
address_table.c.type=='MAIN'))

but unfortunately current relation() code does not support a join of X/ 
Y to Y, unless the join of X/Y is assembled via joined table  
inheritance.    As a workaround, you can wrap your join() in an  
aliased select().   A fix may be available in the next 10 minutes or  
maybe not.

You also could forego the complexity of mapping to a join and just  
modify your Subscriber class to break up the "addresses" collection  
amongst a proxy of the "MAIN" element and a list of the remaining  
elements.  an attribute_mapped_collection could help to accomplish  
this nicely.



On Jan 28, 2009, at 7:22 PM, GHZ wrote:

>
> I have a subscriber and address table.
>
> a subscriber will have one and only one 'MAIN' address.
> I want the subscriber and MAIN address to be represented by one class
> 'Subscriber'.  However, I want that class to have a collection
> 'addresses' which contains other addresses (e.g. old addresses) - (it
> can include the 'MAIN' address too .. or not.. I don't care)
>
>    subscriber_table = Table('subscriber', metadata,
>        Column('id', primary_key=True),
>        autoload=True)
>
>    address_table = Table('address',
>                          metadata,
>                          Column('subscriber_id', ForeignKey
> ('subscriber.id'), primary_key=True),
>                          Column('address_type', primary_key=True),
>                          autoload=True)
>
>
>
>     subscriber_with_default_address = sql.join( subscriber_table.c.id
> == address_table.c.subscriber_id).??? <- something to say
> address_table.type is 'MAIN'
>
>     mapper(Address, address_table)
>
> mapper(Subscriber, subscriber_and_address, properties={
>    'id':[subscriber_table.c.id, address_table.c.subscriber_id],
>    'addresses' : relation(Address, collection_class=Addresses,
> backref='customer')
>    })
>
> a) I can't quite figure out how to say (address.type is default)
> b) even without this I get:
>
> sqlalchemy.exc.ArgumentError: Can't determine relation direction for
> relationshi
> p 'Subscriber.addresses' - foreign key columns are present in both the
> parent an
> d the child's mapped tables.  Specify 'foreign_keys' argument.
>
> if I do specify foreign_keys parameter to the relation function, then
> I still get the same.
>
> Thanks
>
>
> >


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