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.