On 11/18/06, José de Paula Eufrásio Júnior <[EMAIL PROTECTED]> wrote:
>
> So, I want to write a 'count' property to a mapped object, basically
> it'll return the count() of rows where id == something, but I was not
> very sucessfull finding how to count things on SQLA without actually
> selecting the data...
>
> The func.count option counts the total items on the table, I didn't
> find a way to make it count just the "where" results...
>

There are a couple of ways to do this.  If you're using `assign_mapper()`:

ObjectName.count_by(property=foo)

using standard `mapper()`:

session.query(ObjectName).count_by(property=foo)

using a table that has no object (like a many-to-many reference table):

select([func.count(a_random_table)], a_random_table.c.column_name ==
foo).scalar()

Lee

-- 
Lee McFadden

blog: http://www.splee.co.uk
work: http://fireflisystems.com

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to