I have the following tables:

things_table = Table(’thing', self.metadata,
        Column('id', Integer, primary_key=True),
        …
)

comments_table = Table('comments', self.metadata,
        Column('id', Integer, primary_key=True),      # Unique id for this 
comment
        Column('type', Integer),                      # Type of comment 
(feedback, etc)
        …
)

(And the corresponding mapping).

I’m trying to construct a query like this:

    clauseList  = []
    clauseList.append(Look.creation >= start_date_rounded)
    clauseList.append(Look.creation <= end_date)
    clauseList.append(Look.like_count > 0)

    clauseList.append(Comment.creation >= start_date_rounded)
    clauseList.append(Comment.creation <= end_date)
    clauseList.append(Comment.type == CommentTypeLike)
    clauseList.append(Comment.target_id == Look.id)
    condition = and_(*clauseList)

    looks = session.query(Look, Comment, 
                          func.count(Comment.type)).\
            group_by(Look.id).\
            order_by(func.count(Comment.type).desc()).\
            filter(condition).\
            offset(0).\
            limit(count).\
            all()

This fails with :
FROM comments, things 
WHERE comments.target_id = things.id AND comments.type = :type_1' returned no 
FROM clauses due to auto-correlation; specify correlate(<tables>) to control 
correlation manually.
The “comments_table” and “things_table” declaration aren’t visible to the 
function generating the query, but even if I make them visible, and specify :
correlate(things, comments).\
It still fails. 
How can I make this work?

Thanks!




-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to