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.
31caecd97fb56c008e240a8707409c14?d=identicon&s=25 Ruby Quest (rubyquest)
on 2006-12-28 15: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
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 unknown (Guest)
on 2006-12-28 16:20
(Received via mailing list)
On Thu, 28 Dec 2006, Ruby Quest 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 Haines
31caecd97fb56c008e240a8707409c14?d=identicon&s=25 Ruby Quest (rubyquest)
on 2006-12-28 16:28
Thanks kirk Haines!

    It works...

Thanks again
Rubyquest
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 unknown (Guest)
on 2006-12-28 16:32
(Received via mailing list)
On Fri, 29 Dec 2006, Ruby Quest 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 Haines
31caecd97fb56c008e240a8707409c14?d=identicon&s=25 Ruby Quest (rubyquest)
on 2006-12-29 10: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 Haines
This topic is locked and can not be replied to.