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

Rails Edge: check compatibility with .with #204

Open
tagliala opened this issue Jun 27, 2023 · 1 comment
Open

Rails Edge: check compatibility with .with #204

tagliala opened this issue Jun 27, 2023 · 1 comment

Comments

@tagliala
Copy link
Member

tagliala commented Jun 27, 2023

Rails 7.1 will introduce .with to make CTE queries easily

There are no specs in Chronomodel that ensures that this works, we should add one

Database structure is here: https://github.com/ifad/chronomodel/blob/master/spec/support/time_machine/structure.rb

Ref: https://edgeapi.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-with

/cc @dimvic

BUNDLE_GEMFILE=gemfiles/rails_edge.gemfile bundle update

BUNDLE_GEMFILE=gemfiles/rails_edge.gemfile bundle exec rspec spec/chrono_model/
Testing against Active Record 7.1.0.alpha with Arel 10.0.0
@dimvic
Copy link

dimvic commented Jun 29, 2023

CTE queries are really just queries and AR does not add magic on top of them, it is up to the implementation to use plain or temporal query.

So this will look for Post as of as_of_time, having Author that exists in the present

Post
  .as_of(as_of_time)
  .with(authors_cte: Author.all)
  .joins("inner join authors_cte on authors_cte.id = posts.author_id")
  .where(authors_cte: { name: current_author_name })

And explicitly setting as_of on the CTE scope is required to find Post as of as_of_time with Author as of as_of_time

Post
  .as_of(as_of_time)
  .with(authors_cte: Author.as_of(as_of_time).all)
  .joins("inner join authors_cte on authors_cte.id = posts.author_id")
  .where(authors_cte: { name: author_name_as_of })

I have added an example here, sorry for the mistakenly created PR against upstream.

If you think it would be good to include such test cases I can rewrite to follow the spec seeds and style.

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

No branches or pull requests

2 participants