-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from stanleylhs/fix-for-rails-7.1
Override for table name fix for Rails 7.1
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
lib/ransack_ui/ransack_overrides/adapters/active_record/context.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |