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

Preserve RECURSIVE flag of CTE relations when they are merged. #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsnelling
Copy link

This pull request fixes what I think to be a bug in the handling of recursive CTEs during merges.

Queries like the following:
Tag.all.merge(Tag.with.recursive(recursive: Tag.where(tag: 'tag')))
Tag.with.recursive(recursive: Tag.where(tag: 'tag')).merge(Tag.all)

would both be expected to produce a query like:
WITH RECURSIVE "recursive"
AS ( SELECT "tags".*
FROM "tags"
WHERE "tags"."tag" = 'tag')
SELECT "tags".*
FROM "tags"

but currently only the second one would. The first would lose the recursive flag
during merge and result in:
WITH "recursive"
AS ( SELECT "tags".*
FROM "tags"
WHERE "tags"."tag" = 'tag')
SELECT "tags".*
FROM "tags"

Adding :recursive to ActiveRecord::Relation::Merger#normal_values
and a #recursive! method to ActiveRecord::QueryMethods the expected behavior
regardless of the direction of the merge.

Closes # .

Changes proposed in this pull request

Queries like the following:
Tag.all.merge(Tag.with.recursive(recursive: Tag.where(tag: 'tag')))
Tag.with.recursive(recursive: Tag.where(tag: 'tag')).merge(Tag.all)

would both be expected to produce a query like:
WITH RECURSIVE "recursive"
   AS ( SELECT "tags".*
          FROM "tags"
         WHERE "tags"."tag" = 'tag')
SELECT "tags".*
  FROM "tags"

but currently only the second one would. The first would lose the recursive flag
during merge and result in:
WITH "recursive"
   AS ( SELECT "tags".*
          FROM "tags"
         WHERE "tags"."tag" = 'tag')
SELECT "tags".*
  FROM "tags"

Adding :recursive to ActiveRecord::Relation::Merger#normal_values
and a #recursive! method to ActiveRecord::QueryMethods the expected behavior
regardless of the direction of the merge.
@edpaget
Copy link
Collaborator

edpaget commented Jan 12, 2017

Thank you @jsnelling I will review this weekend and hopefully merge

@jsnelling
Copy link
Author

hey @edpaget, I wanted to check in and see if there was anything else that you needed from me on this PR?

@Papipo
Copy link

Papipo commented Aug 17, 2018

:(

@jsnelling
Copy link
Author

@Papipo unfortunately, it doesn't seem that this project is active anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants