On Oct 5, 2010, at 11:04 AM, Chris Withers wrote:
> Hi All,
>
> Start off with a base.py module:
>
> from sqlalchemy.ext.declarative import declarative_base
> Base = declarative_base()
>
> Now, say we have a module, a.py:
>
> from sqlalchemy import *
> from base import Base
>
> class Something(Base):
> __tablename__ = 'foo'
> id = Column('id', Integer, primary_key=True)
>
> ...and another module, b.py:
>
> from sqlalchemy import *
> from base import Base
>
> class Something(Base):
> __tablename__ = 'bar'
> id = Column('id', Integer, primary_key=True)
>
> ...and finally, a third module, c.py:
>
> from sqlalchemy import *
> from sqlalchemy.orm import relationship
> from base import Base
>
> import a,b
>
> class AnotherThing(Base):
> __tablename__ = 'baz'
> id = Column('id', Integer, primary_key=True)
> addresses = relationship("Something")
>
> ...what table will that relationship be to?
>
> >>> import c
> >>> c.AnotherThing._decl_class_registry['Something']
> <class 'b.Something'>
>
> I think an exception should be raised if a class name already exists in
> _decl_class_registry when the assignment is made in _as_declarative.
yeah definitely, though in 0.6 it needs to be a warning to start since some
folks might be doing this semi-intentionally.
> Are there any cases where it would be legit to have one class override
> another in _decl_class_registry in this way?
> If the answer is no, I'll commit a test and patch asap...
>
> cheers,
>
> Chris
>
> PS: Also, in the above, how come no foreign keys are created?
theres no usage of ForeignKey() or ForeignKeyConstraint().
--
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.