ruby - Rails Concatenated Query Result "where" -
i have concatenated 2 query results , limit results based on particular criteria.
def all_notifications return (user_project_notifications+followed_comments).sort_by(&:created_at).reverse end i'd limit all_notifications come after time, like:
def new_notifications(notifications_last_viewed) return all_notifications.where('created_at >?, notifications_last_viewed) end however, i'm getting error undefined method `where' array:...
how can perform "where" query on concatenated result?
you can't directly, because after apply 1 of typical array (or enumerable) methods (for example "+") on activerecord::relation, returns array instance, doesn't have activerecord methods.
i think should fetch user_project_notifications , followed_comments in 1 query "or" - have activerecord::relation instance, on can call scope methods, order or where.
Comments
Post a Comment