Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for recursive CTEs in ActiveRecord #51601

Merged
merged 1 commit into from May 2, 2024

Commits on May 2, 2024

  1. Add support for recursive CTE in Active Record

    ```ruby
    Post.with_recursive(
      post_and_replies: [
        Post.where(id: 42),
        Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
      ]
    )
    ```
    
    Generates the following SQL:
    
    ```sql
    WITH RECURSIVE "post_and_replies" AS (
      (SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
      UNION ALL
      (SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
    )
    SELECT "posts".* FROM "posts"
    ```
    ClearlyClaire authored and byroot committed May 2, 2024
    Configuration menu
    Copy the full SHA
    fc26e44 View commit details
    Browse the repository at this point in the history