I just ended up taking advantage of the fact that you can pass attribute names as strings to join, but thanks for the tips!
On Tue, Jan 12, 2016 at 9:25 AM, Michael Bayer <[email protected]> wrote: > > > Two options - either use back_populates format (search the docs) to set > up bidirectional relationships, or call configure_mappers() after the model > classes have been defined. > > On Jan 11, 2016, at 3:47 PM, Sam Raker <[email protected]> wrote: > > Using SQLAlchemy 1.0.9's declarative extension, I've got a many-to-one > relationship defined thusly: > > class Article(Base): > ... > publisher_id = schema.Column(sqltypes.Integer, schema.ForeignKey(' > publishers.id')) > ... > class Publisher(Base): > __tablename__ = 'publishers' > ... > articles = relationship('Article', backref='publisher') > > > I've got some code I'd like to test that looks like this: > > articles = session.query(Article).filter(...).join(Article.publisher). > filter(Publisher.name ==...)... > > The code works fine, but while trying to test it with python 2.7's > unittest module, I keep getting > AttributeError: type object 'Article' has no attribute 'publisher' > > How do I resolve this? I'm importing both Article and Publisher into my > test file. I _really_ don't want to have to connect to a local db just to > get instrumented attributes to work properly, and I don't want to have to > refactor my code to use Article.publisher_id--as it'd involve either > hard-coding (brittle) or two separate ORM/SQL calls (obnoxious)--just to > make tests work. > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/mrqsB-YyCsw/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- Sam Raker Application Developer [email protected] 30 W 24th St., 12th Floor New York, NY 10010 *Download the Elite Daily iOS App <https://itunes.apple.com/us/app/elite-daily/id1032458504?mt=8>* -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
