Skip to content

Commit

Permalink
Merge pull request #25 from stanleylhs/fix-for-rails-7.1
Browse files Browse the repository at this point in the history
Override for table name fix for Rails 7.1
  • Loading branch information
steveyken authored Sep 13, 2024
2 parents a9e67fd + d2acbb6 commit 2d57d65
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ransack_ui/ransack_overrides/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'ransack/adapters/active_record/context.rb'

module Ransack
module Adapters
module ActiveRecord
Context.class_eval do
def type_for(attr)
return nil unless attr && attr.valid?
relation = attr.arel_attribute.relation
name = attr.arel_attribute.name.to_s
table = relation.respond_to?(:table_name) ? relation.table_name : relation.name
schema_cache = self.klass.connection.schema_cache
unless schema_cache.send(:data_source_exists?, table)
raise "No table named #{table} exists."
end
attr.klass.columns.find { |column| column.name == name }.type
end
end
end
end
end

0 comments on commit 2d57d65

Please sign in to comment.