activerecord - Rails combine results of multiple includes statements -


the scenario need generate notifications on updates. have updates possible on 3 tables namely products, users , notifications. user can "follow" of 3 things , if there updates in either of three, user should notified.

the relations are

notification belongs user

notification belongs nook

notification belongs product

product has many followers(followers relation user table)

user has many followers

nook has many followers

when try user id = 1:

notification.includes(:product => :followers).where("relations.follower_id = ?", 1)  notification.includes(:user => :followers).where("relations.follower_id = ?", 1)  notification.includes(:nook => :followers).where("relations.follower_id = ?", 1) 

all above 3 work fine when executed individually.

but when do:

notification.includes(:product => :followers, :user => :followers, :nook => :followers).where("relations.follower_id = ?", 1) 

it not give me desired result. new rails want know how achieve thing mentioned below: want combined result of above 3 queries using single query because want sorting operations on combined results of three. type of "or" operation of 3 queries.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -