keplerproject / orbit

Orbit is an MVC web framework for Lua.
http://keplerproject.github.io/orbit/
118 stars 35 forks source link

Impossible to retrieve number of rows in model table #5

Closed remram44 closed 10 years ago

remram44 commented 13 years ago

It seems to me that counting the number of model instances can only be achieved through find_all() and the # operator. This is inefficient...

The Orbit tutorial uses a dedicated field in the "post" model to know how many "comment"s are associated with it, but that doesn't feel right (or even repeatable in other cases where a condition should be passed to a_model:find_all()).

Going through the current code for build_query() I don't think I can add this feature easily.

kognix commented 11 years ago

Instead or retrieving all rows / instances and counting them you can use the count(*) aggregate function:

e.g. count = posts:find_all("", { fields = {"count(*)" } })

kognix commented 10 years ago

Can we close this issue?

hishamhm commented 10 years ago

I guess so!