Seth wrote:
>
> I'm trying to set up a relation from one table to another that will
> give me a count of the unique user_id's that have posted a comment to
> a post.
>
> For example: I've set up "post" as the parent table, and "comments" as
> the child table (with post_id, user_id, comment_body, etc). What I
> want to be able to do is once I do a "post = Session.query()", have
> access to a "post.distinct_users" attribute which would essentially be
> a "COUNT(DISTINCT(user_id))" on the comments table.
>
> I'm using DeclaritiveBase. If you a paste of my current setup I'd be
> happy to oblige.

use a recipe almost identical to the second example in
http://www.sqlalchemy.org/docs/05/mappers.html#sql-expressions-as-mapped-attributes
.   you just need to add a distinct() inside the count().



>
> Thanks,
> Seth
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to