开发者

How do I find all squads attending all events whose start date is greater than some value?

My two models are straightforward:

squad.rb
  belongs_to :event

event.rb
  has_many :squads

I've got a rake task t开发者_运维技巧hat generates rankings based on the results of each squad at each event.

I'm in my second year and need to update my rankings script to only pull squads attending events whose start date is greater than 2010-10-30.

I'm sure this a very easy thing to do, but I can't seem to figure it out.

My app is running on 2.3.8 for now.


squad.rb

named_scope :scope_name, :include => :event, :conditions => [ "events.start_date > ?", YOUR_DATE]

Then use

Squad.scope_name

I hope i didn't any mistakes)


Squad.all(:joins => :event, :conditions => "events.start_date > '2010-10-30'")

or

date = "2010-10-30"
Squad.all(:joins => :event, :conditions => ["events.start_date > ?", date])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜