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 7.2+ support #132

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion baby_squeel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|

spec.files = Dir.glob('{lib/**/*,*.{md,txt,gemspec}}')

spec.add_dependency 'activerecord', '>= 6.1.5', '< 7.2'
spec.add_dependency 'activerecord', '>= 6.1.5', '< 7.3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add Rails 7.1 and 7.2 to the testmatrix .github/workflows/build.yml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of a noob on this one - would it need to be activerecord: ["~> 6.1", "~> 7.2"] in build.yml?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be activerecord: ["~> 6.1", "~> 7.0" "~> 7.1" "~> 7.2"] so everything is tested. But I'm not an expert here as well.

spec.add_dependency 'ransack', '~> 4.1'

spec.add_development_dependency 'bundler', '~> 2'
Expand Down
5 changes: 5 additions & 0 deletions lib/baby_squeel/active_record/version_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class VersionHelper
# ::ActiveRecord::VERSION::MAJOR > 7 ||
# ::ActiveRecord::VERSION::MAJOR == 7 && ::ActiveRecord::VERSION::MINOR >= 1
# end

def self.at_least_7_2?
::ActiveRecord::VERSION::MAJOR == 7 && ::ActiveRecord::VERSION::MINOR >= 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add ::ActiveRecord::VERSION::MAJOR > 7 || if the changes also apply for Rails 8.0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear if this will work on rails 8 at this time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the method suggests that it will apply to Rails 8.0.

I believe that the Associations::AliasTracker is not reverting to a simple connection.

Even if there are issues in Version 8, it would be simpler to start with the Rails 7.2 changes rather than the Rails 7.1 changes.

ActiveRecord 8.0.0.rc2 is green with the changes you made. 👍

end

end
end
end
2 changes: 1 addition & 1 deletion lib/baby_squeel/join_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def build(relation, buckets)

join_list = join_nodes + joins

alias_tracker = Associations::AliasTracker.create(relation.klass.connection, relation.table.name, join_list)
alias_tracker = Associations::AliasTracker.create(BabySqueel::ActiveRecord::VersionHelper.at_least_7_2? ? relation.klass.connection.pool : relation.klass.connection, relation.table.name, join_list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please point to the Documentation why this change is needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first param for the init method for Associations::AliasTracker was changed to accept a pool now: https://github.com/rails/rails/blob/v7.2.1.2/activerecord/lib/active_record/associations/alias_tracker.rb#L9

join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::InnerJoin)
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)

Expand Down
2 changes: 1 addition & 1 deletion lib/baby_squeel/nodes/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BabySqueel
module Nodes
# This proxy class allows us to quack like any arel object. When a
# method missing is hit, we'll instantiate a new proxy object.
class Proxy < ActiveSupport::ProxyObject
class Proxy < BasicObject
# Resolve constants the normal way
def self.const_missing(name)
::Object.const_get(name)
Expand Down