Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
abMatGit authored Sep 25, 2024
2 parents f55d933 + 2d56e78 commit 88de5ab
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
fail-fast: false
matrix:
rails:
- 7-2-stable
- v7.1.0
- v7.0.3
- v6.1.6
ruby:
- 3.2.2
- 3.1.4
- 3.0.6
env:
DB: sqlite3
RAILS: ${{ matrix.rails }}
Expand All @@ -39,13 +39,13 @@ jobs:
fail-fast: false
matrix:
rails:
- 7-2-stable
- v7.1.0
- v7.0.3
- v6.1.6
ruby:
- 3.2.2
- 3.1.4
- 3.0.6
env:
DB: mysql
RAILS: ${{ matrix.rails }}
Expand Down Expand Up @@ -74,13 +74,13 @@ jobs:
fail-fast: false
matrix:
rails:
- 7-2-stable
- v7.1.0
- v7.0.3
- v6.1.6
ruby:
- 3.2.2
- 3.1.4
- 3.0.6
env:
DB: postgres
RAILS: ${{ matrix.rails }}
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

## 4.2.1 - 2024-8-11

* Fix Rails 7.1.x compatibility

## 4.2.0 - 2024-7-10

* Add Rails 7.2 support by @robinator and @gregmolnar

## 4.1.0 - 2023-10-23

### 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gemspec

gem 'rake'

rails = ENV['RAILS'] || '7-1-stable'
rails = ENV['RAILS'] || '7-2-stable'

rails_version = case rails
when /\// # A path
Expand All @@ -15,7 +15,7 @@ rails_version = case rails
end

gem 'faker'
gem 'sqlite3'
gem 'sqlite3', '~> 1.4'
gem 'pg'
gem 'pry'
gem 'byebug'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are advanced searching solutions around, like ElasticSearch or Algolia. **

Ready to move beyond the basics? Use **advanced features** like i18n and extensive configuration options.

Ransack is supported for Rails 7.0, 6.1 on Ruby 3.0 and later.
Ransack is supported for Rails 7.2, 7.1, 7.0, 6.1 on Ruby 3.1 and later.

## Installation

Expand Down
55 changes: 55 additions & 0 deletions lib/polyamorous/activerecord/join_association_7_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Polyamorous
module JoinAssociationExtensions
# Same as #join_constraints, but instead of constructing tables from the
# given block, uses the ones passed
def join_constraints_with_tables(foreign_table, foreign_klass, join_type, alias_tracker, tables)
joins = []
chain = []

reflection.chain.each.with_index do |reflection, i|
table = tables[i]

@table ||= table
chain << [reflection, table]
end

base_klass.with_connection do |connection|
# The chain starts with the target table, but we want to end with it here (makes
# more sense in this context), so we reverse
chain.reverse_each do |reflection, table|
klass = reflection.klass

join_scope = reflection.join_scope(table, foreign_table, foreign_klass)

unless join_scope.references_values.empty?
join_dependency = join_scope.construct_join_dependency(
join_scope.eager_load_values | join_scope.includes_values, Arel::Nodes::OuterJoin
)
join_scope.joins!(join_dependency)
end

arel = join_scope.arel(alias_tracker.aliases)
nodes = arel.constraints.first

if nodes.is_a?(Arel::Nodes::And)
others = nodes.children.extract! do |node|
!Arel.fetch_attribute(node) { |attr| attr.relation.name == table.name }
end
end

joins << table.create_join(table, table.create_on(nodes), join_type)

if others && !others.empty?
joins.concat arel.join_sources
append_constraints(connection, joins.last, others)
end

# The current table in this iteration becomes the foreign table in the next
foreign_table, foreign_klass = table, klass
end

joins
end
end
end
end
4 changes: 4 additions & 0 deletions lib/polyamorous/polyamorous.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module Polyamorous
require 'polyamorous/activerecord/join_dependency'
require 'polyamorous/activerecord/reflection'

if ::ActiveRecord.version >= ::Gem::Version.new("7.2")
require "polyamorous/activerecord/join_association_7_2"
end

ActiveRecord::Reflection::AbstractReflection.send(:prepend, Polyamorous::ReflectionExtensions)

Polyamorous::JoinDependency.send(:prepend, Polyamorous::JoinDependencyExtensions)
Expand Down
4 changes: 2 additions & 2 deletions lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def klassify(obj)
#
def join_sources
base, joins = begin
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
alias_tracker = @object.alias_tracker
constraints = @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)

[
Expand Down Expand Up @@ -278,7 +278,7 @@ def build_joins(relation)

join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)

alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
alias_tracker = relation.alias_tracker(join_list)
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
join_nodes.each do |join|
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Ransack
VERSION = '4.1.1'
VERSION = '4.2.1'
end

0 comments on commit 88de5ab

Please sign in to comment.