##Merge many has_many
def get_fb_users
FacebookUser.from("
(
(
#{self.facebook_recipients_users.to_sql}
) union (
#{self.facebook_users.to_sql}
)
) #{FacebookUser.table_name}
")
end
Peut aussi être fait autrement (mais BEAUCOUP moins rapide):
def get_fb_users
fromable_users = self.facebook_users.pluck(:id)
postable_users = self.facebook_recipients_users.pluck(:id)
all_users_ids = (fromable_users+postable_users).uniq
res = FacebookUser.where(id: all_users_ids)
end