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 => ...
精彩评论