Forum: Ruby Syntax for db count query needed

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ruby Q. (Guest)
on 2006-12-28 16:36
can any one tell me the controller syntax for db record count?

I want to specify this mysql query syntax in controller

  select count(*) from tablename where user_id=7;

  what is the controller syntax similar to the above sql quert?


thanks and regards
Rubyquest
unknown (Guest)
on 2006-12-28 17:20
(Received via mailing list)
On Thu, 28 Dec 2006, Ruby Q. wrote:

> can any one tell me the controller syntax for db record count?
>
> I want to specify this mysql query syntax in controller
>
>  select count(*) from tablename where user_id=7;
>
>  what is the controller syntax similar to the above sql quert?

Sure!  I do it like this:

count = ksdbh.count(:Tablename) {|r| r.user_id == 7}

Other people probably do it differently, though.  Details are important
when asking a "How do I...?" question.

I imagine that you are actually asking how to do that using
ActiveRecord,
right?  If so, while you will probably get a correct answer for AR from
someone on this list, the better place to ask those questions is the
Rails
list.


Thanks,

Kirk H.
Ruby Q. (Guest)
on 2006-12-28 17:28
Thanks kirk Haines!

    It works...

Thanks again
Rubyquest
unknown (Guest)
on 2006-12-28 17:32
(Received via mailing list)
On Fri, 29 Dec 2006, Ruby Q. wrote:

> Thanks kirk Haines!
>
>    It works...
>
> Thanks again

That works for you?  What ORM are you using?  That was not AR syntax,
but
rather, syntax for the Kansas ORM.


Kirk H.
Ruby Q. (Guest)
on 2006-12-29 11:40
NO...i used below method and it works.

 @itemCount=Item.count(:all, :joins=>"my table joins goes here",
:conditions =>["my conditions goes here"];


sorry for the confusion....

Thanks
RQ


> That works for you?  What ORM are you using?  That was not AR syntax,
> but
> rather, syntax for the Kansas ORM.
>
>
> Kirk H.
This topic is locked and can not be replied to.