Skip to content

Commit

Permalink
TableMetadata#associated_table look for reflections by table_name
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn617 committed Mar 25, 2024
1 parent 61a3e61 commit f177e1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
beaneater (1.1.3)
bigdecimal (3.1.5)
bigdecimal (3.1.7)
bindex (0.8.1)
bootsnap (1.17.0)
msgpack (~> 1.2)
Expand All @@ -181,7 +181,7 @@ GEM
cgi (0.4.1)
chef-utils (18.3.0)
concurrent-ruby
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crack (0.4.5)
rexml
Expand All @@ -205,8 +205,7 @@ GEM
delayed_job (>= 3.0, < 5)
digest-crc (0.6.5)
rake (>= 12.0.0, < 14.0.0)
drb (2.2.0)
ruby2_keywords
drb (2.2.1)
erubi (1.12.0)
et-orbi (1.2.7)
tzinfo
Expand Down Expand Up @@ -271,6 +270,8 @@ GEM
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
google-protobuf (3.25.1)
google-protobuf (3.25.1-x86_64-darwin)
google-protobuf (3.25.1-x86_64-linux)
googleauth (1.9.1)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
Expand All @@ -279,7 +280,7 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
hashdiff (1.1.0)
i18n (1.14.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
Expand All @@ -288,10 +289,10 @@ GEM
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.1)
irb (1.11.0)
io-console (0.7.2)
irb (1.12.0)
rdoc
reline (>= 0.3.8)
reline (>= 0.4.2)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
Expand Down Expand Up @@ -328,7 +329,7 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.21.1)
minitest (5.21.2)
minitest-bisect (1.7.0)
minitest-server (~> 1.0)
path_expander (~> 1.1)
Expand All @@ -350,22 +351,22 @@ GEM
mysql2 (0.5.5)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-imap (0.4.9)
net-imap (0.4.10)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.4.0)
net-smtp (0.4.0.1)
net-protocol
nio4r (2.7.0)
nokogiri (1.16.0)
nio4r (2.7.1)
nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.0-x86_64-darwin)
nokogiri (1.16.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.0-x86_64-linux)
nokogiri (1.16.3-x86_64-linux)
racc (~> 1.4)
os (1.1.4)
parallel (1.24.0)
Expand All @@ -390,7 +391,7 @@ GEM
pg (>= 1.1, < 2.0)
raabro (1.4.0)
racc (1.7.3)
rack (3.0.8)
rack (3.0.10)
rack-cache (1.15.0)
rack (>= 0.4)
rack-session (2.0.0)
Expand All @@ -413,7 +414,7 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rbtree (0.4.6)
rdoc (6.6.2)
rdoc (6.6.3.1)
psych (>= 4.0.0)
redcarpet (3.2.3)
redis (5.0.8)
Expand All @@ -423,7 +424,7 @@ GEM
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.8.3)
reline (0.4.1)
reline (0.5.0)
io-console (~> 0.5)
representable (3.2.0)
declarative (< 0.1.0)
Expand Down Expand Up @@ -545,7 +546,7 @@ GEM
railties (>= 6.0.0)
terser (1.1.20)
execjs (>= 0.3.0, < 3)
thor (1.3.0)
thor (1.3.1)
timeout (0.4.1)
tomlrb (2.0.3)
trailblazer-option (0.1.2)
Expand Down Expand Up @@ -579,7 +580,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.12)
zeitwerk (2.6.13)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/table_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def associated_with?(table_name)
end

def associated_table(table_name)
reflection = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.singularize)
reflection = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.singularize) || klass.reflections.values.detect { |reflection| reflection.table_name == table_name }

if !reflection && table_name == arel_table.name
return self
Expand Down

0 comments on commit f177e1a

Please sign in to comment.