On 11/18/06, Lee McFadden <[EMAIL PROTECTED]> wrote:
>
> 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()

Wooo, that one hit the spot :)
It's exactly in a many-to-many reference table, the part after the
function is the 'where' righ? :)

Any idea how 'intensive' is that? Like, in big tables or if used many
times it'll show a big hit on performance or most of the engines/db's
cache this type of data (btw, I'm using MySQL innodb tables).

Thanks

-- 
José de Paula Eufrásio Júnior
aka coredump
http://core.eti.br

--~--~---------~--~----~------------~-------~--~----~
 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