开发者

How to find by an attribute through a join model?

开发者 https://www.devze.com 2023-02-01 01:31 出处:网络
How do I find users who are subscribed to skills which have positions created in the last day? I wish I could:User.find(all).where.skills.positions(\'created_at > ?\', Time.now - 1.day)

How do I find users who are subscribed to skills which have positions created in the last day?

I wish I could: 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 => :sub开发者_如何转开发scriptions


I'm not sure I've understood your answer completely, but you should be able to do

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])

Hope it helps.

0

精彩评论

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

关注公众号