如何通过连接模型找到属性?

时间:2010-12-26 23:16:05

标签: ruby-on-rails

如何找到订阅了在最后一天创建职位的技能的用户?

我希望我能:User.find(all).where.skills.positions('created_at>?',Time.now - 1.day)

Company      
has_many :positions
has_many :skills, :through => :positions

Position    
belongs_to :company
belongs_to :skill

Skill
has_many :positions
has_many :companies, :through => :positions
has_many :subscriptions
has_many :users, :through => :subscriptions

Subscription
belongs_to :skill
belongs_to :user

User
has_many :subscriptions
has_many :skills, :through => :subscriptions

1 个答案:

答案 0 :(得分:1)

我不确定我完全理解你的答案,但你应该能够做到

User.all.include({ :skills => :positions }).where(['positions.created_at > ? AND positions.created_at < ?',(Time.now - 1.day).at_beginning_of_day, (Time.now - 1.day).at_end_of_day])

希望它有所帮助。