Here's what I had in mind. This set of mappings compiles without errors in 0.3.11:
from sqlalchemy import * from sqlalchemy.orm import * engine = create_engine('sqlite://') meta = MetaData(engine) a = Table('a', meta, Column('id', Integer, primary_key=True)) b = Table('b', meta, Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey('a.id'))) class A(object):pass class B(object):pass class C(object):pass mapper(A, a, properties={ 'b':relation(B, backref='a') }) mapper(B, b, properties={ 'a':relation(A, backref='b') }) compile_mappers() Barry ----- Original Message ---- From: Michael Bayer <[EMAIL PROTECTED]> To: sqlalchemy@googlegroups.com Sent: Wednesday, October 24, 2007 4:41:46 PM Subject: [sqlalchemy] Re: Declaring a relationship twice - could SqlAlchemy auto-detect problems like this? On Oct 24, 2007, at 4:16 PM, Barry Hart wrote: This subject came up on the TurboGears list and someone suggested I post here. I noticed a while back that in SqlAlchemy 0.3.x, if you have two mapped classes A and B, and you define the same relationship (with a backref) on both classes, you won't get an error message but the two relationships interfere with each other. For example, you might set the value of the relationship and it won't be saved to the database. Would it be possible to detect and flag this as an error at model compilation time? hey Barry - that would be a bug, and I cant reproduce it, at least the bug i think youre describing, in neither 0.3 nor 0.4: from sqlalchemy import * from sqlalchemy.orm import * engine = create_engine('sqlite://') meta = MetaData(engine) a = Table('a', meta, Column('id', Integer, primary_key=True)) b = Table('b', meta, Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey('a.id'))) c = Table('c', meta, Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey('a.id'))) class A(object):pass class B(object):pass class C(object):pass mapper(A, a) mapper(B, b, properties={ 'a':relation(A, backref='thebackref') }) mapper(C, c, properties={ 'a':relation(A, backref='thebackref') }) compile_mappers() output: <stack trace> sqlalchemy.exceptions.ArgumentError: Backrefs do not match: backref 'thebackref' expects to connect to <class '__main__.C'>, but found a backref already connected to <class '__main__.B'> can you produce a test case ? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---