Hi,

I'm trying to resolve a circular dependency error between two tables
referring to each other. I tried all kinds of tricks found in the
mailinglist archive and tried to apply the hints given in the
exception messages. However, the suggested solution of the last
exception is not acceptable:

sqlalchemy.exc.ArgumentError: Could not locate any equated, locally
mapped column pairs for primaryjoin condition 'test_contact.address_id
= :param_1' on relation TestContact.address. For more relaxed rules on
join conditions, the relation may be marked as viewonly=True.

You can find the code below. Basically what I want to achieve is for
the contact to have a default address and also allowing it to have
other_addresses. SQLalchemy seems to think it needs to update the
contact_id for the default address too.

Any idea how to resolve this?

Thanks!
Konrad

-------------------------------------------------------------------------------------------
from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relation, backref

DeclarativeBase = declarative_base()

class TestContact(DeclarativeBase):
    __tablename__ = 'test_contact'
    id = Column(Integer, primary_key=True)
    address_id = Column(Integer, ForeignKey('test_address.id',
use_alter=True, name='address_id_fk'), default=None)

    address = relation('TestAddress',
primaryjoin=address_id=='test_address.id', foreign_keys=[address_id])

class TestAddress(DeclarativeBase):
    __tablename__ = 'test_address'
    id = Column(Integer, primary_key=True)
    contact_id = Column(Integer, ForeignKey('test_contact.id'),
index=True, default=None)

    contact = relation(TestContact, backref=backref('other_addresses',
order_by=id),
        uselist=False, primaryjoin=contact_id==TestContact.id)

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