Frank Kim wrote:
> I have a model, let's call it Player.
>
> It has many Trophies.
>
> How do I do a simple query in Rails in my controller that will return
> let's say all Players that have more than 5 tropies?
>
> Sorry for the dumb question but I can't figure it out. :-)
>
> --
> Frank Kim
>
On Feb 15, 6:59 am, Peter wrote:
> And you can actually represent this in AR friendly syntax; no console
> in front of me but its something like
>
> Player.find(:select => "players.id", :joins => :trophies, :group =>
> 'players.id', :having => 'count(players.id) > 5')
>
> Downside of this is tha
And you can actually represent this in AR friendly syntax; no console
in front of me but its something like
Player.find(:select => "players.id", :joins => :trophies, :group =>
'players.id', :having => 'count(players.id) > 5')
Downside of this is that the returned objects in this case would only
h
Thanks everyone, that was really helpful!
On Sun, Feb 14, 2010 at 4:31 AM, Frederick Cheung
wrote:
>
>
> On Feb 14, 6:54 am, Frank Kim wrote:
>> I have a model, let's call it Player.
>>
>> It has many Trophies.
>>
>> How do I do a simple query in Rails in my controller that will return
>> let's
On Feb 14, 6:54 am, Frank Kim wrote:
> I have a model, let's call it Player.
>
> It has many Trophies.
>
> How do I do a simple query in Rails in my controller that will return
> let's say all Players that have more than 5 tropies?
>
> Sorry for the dumb question but I can't figure it out. :-)
The best way to do it is to set a counter_cache for the trophies.
Example:
class Trophy < ActiveRecord::Base
belongs_to :player, :counter_cache => true
You'll also have to create an integer column called trophies_count in
the players table. If you already have data in there, you'll need to
upda
6 matches
Mail list logo