I'm not sure if something broke during an upgrade, or if I just had bad 
tests and this was always an issue (I am assuming the latter!)

I need to duplicate a relationship on a sqlalchemy ORM declarative object.

I was hoping i could just do this (or at one point i could!)


class Foo(DeclaredTable):
    bar_id = Column(Integer, ForeignKey("bar.id"), nullable=True)
    bar = relationship("Bar", primaryjoin="Foo.bar_id ==Bar.id", uselist=
False)
    bar_alt = bar


While I can address `fooInstance.bar_alt` with ease,  I trigger an 
AttributeError.  The second item seems to become the 'active' attribute and 
the first item is unaccessible.

AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' 
object associated with Foo.bar has an attribute '_supports_population'

There seems to be a workaround where I do this:

class Foo(DeclaredTable):
    bar_id = Column(Integer, ForeignKey("bar.id"), nullable=True)
    bar = relationship("Bar", primaryjoin="Foo.bar_id ==Bar.id", uselist=
False)

Foo.bar_alt = Foo.bar

However, if there is a better way I would appreciate knowing it.  I would 
prefer to not monkeypatch the class like this for readability.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/a2c99f0c-5af1-4d98-9d0c-fc368a585b1b%40googlegroups.com.

Reply via email to