开发者

Condition on a sub table in rails

开发者 https://www.devze.com 2022-12-10 19:13 出处:网络
I have no good title for this question, but my problem is to set a conditon for my sub-table in rails

I have no good title for this question, but my problem is to set a conditon for my sub-table in rails I have a model named "users" and another named "hours", h开发者_如何学JAVAours is set to "belongs_to :users" and the users-model has "has_many :hours"

But my problem is when I try to fetch the users, but just the hours added this month. I want this to happen only in the Index action.

How can I set a condition for my sub table?


class SomeController
  def index
    Hours.all(:include => [:user], :conditions => "added_this_month is null")
  end
end


has_many can use :conditions

has_many :hours, :conditions => ...

0

精彩评论

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