Hacker News new | ask | show | jobs
by rurabe 1267 days ago
Big fan of raw sql, but practically speaking (as it relates to developing with rails) CTEs can be rewritten as subqueries, the advantage being that they are linear instead of nested in SQL.

With AR queries you can do the same and make it linear in ruby (and then the computer doesn't really care if your sql is nested)

    last_three_posts = Post.limit(3).order(created_at: :desc)
    @posts = Comment.where(post_id: last_three_posts)