I can do this -

comment_count_subquery = meta.Session.query(Comment.article_id,
func.count('*').label('article_comment_count')).group_by
(Comment.article_id).subquery()
query = meta.Session.query(Article,
comment_count_subquery.c.article_comment_count)

but when I do it like this -

query = meta.Session.query(Article)
comment_count_subquery = meta.Session.query(Comment.article_id,
func.count('*').label('article_comment_count')).group_by
(Comment.article_id).subquery()
query.add_entity(comment_count_subquery.c.article_comment_count)

I get the error

 AttributeError: 'NoneType' object has no attribute 'with_polymorphic'

Why won't it work this way? And what is the correct way to do this? I
wish to use add_entity because sometimes the comment count does not
need to be included.

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to