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

Fixes bug when table do not exists (join) #164

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions Gemfile
Expand Up @@ -3,10 +3,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in postgres_ext.gemspec
gemspec
unless ENV['CI']
if RUBY_PLATFORM =~ /java/
gem 'ruby-debug'
else
gem 'byebug'
end
gem 'byebug'
Copy link
Collaborator

Choose a reason for hiding this comment

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

@danmcclain I'm going to clean this PR up and merge it since it seems useful. Do you want this part in the final result?

end
gem 'fivemat'
10 changes: 8 additions & 2 deletions lib/postgres_ext/active_record/relation/predicate_builder.rb
Expand Up @@ -5,8 +5,14 @@ class PredicateBuilder # :nodoc:
def self.build(attribute, value)
case value
when Array
engine = attribute.relation.engine
column = engine.connection.schema_cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s }
column = case attribute.try(:relation)
when Arel::Nodes::TableAlias, NilClass
else
cache = attribute.relation.engine.connection.schema_cache
if cache.table_exists? attribute.relation.name
cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s }
end
end
if column && column.respond_to?(:array) && column.array
attribute.eq(value)
else
Expand Down
Expand Up @@ -10,8 +10,14 @@ module ArrayHandlerPatch

included do
def call_with_feature(attribute, value)
engine = attribute.relation.engine
column = engine.connection.schema_cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s }
column = case attribute.try(:relation)
when Arel::Nodes::TableAlias, NilClass
else
cache = attribute.relation.engine.connection.schema_cache
if cache.table_exists? attribute.relation.name
cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s }
end
end
if column && column.respond_to?(:array) && column.array
attribute.eq(value)
else
Expand Down
8 changes: 5 additions & 3 deletions lib/postgres_ext/arel/4.1/visitors/postgresql.rb
Expand Up @@ -5,15 +5,17 @@ module Visitors
class PostgreSQL
private

def visit_Array o, a
def visit_Array o, a
Copy link
Contributor

Choose a reason for hiding this comment

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

Please kill the whitespace at the end of this line

column = case a.try(:relation)
when Arel::Nodes::TableAlias, NilClass
# noop Prevent from searching for table alias name in schema cache
# which won't exist for aliased table when used with Single Table
# Inheritance. see dockyard/postgres_ext#154
else
a.relation.engine.connection.schema_cache.columns(a.relation.name)
.find { |col| col.name == a.name.to_s }
cache = a.relation.engine.connection.schema_cache
if cache.table_exists? a.relation.name
cache.columns(a.relation.name).find { |col| col.name == a.name.to_s }
end
end

if column && column.respond_to?(:array) && column.array
Expand Down