mysql ActiveRecord查询将id替换为null

3ks5zfa0  于 2023-06-04  发布在  Mysql
关注(0)|答案(1)|浏览(448)

我已经将rails应用程序从5.X升级到6.X,ruby 2.5.X升级到3.1.2,而且我的应用程序使用了apartmentgem,它不支持rails 6,所以我按照建议使用了ros-apartment,但仍然不工作。

User.find 1
   User Load (54.9ms)  SELECT `intello_v2`.`users`.* FROM `intello_v2`.`users` WHERE `intello_v2`.`users`.`deleted_at` IS NULL AND `intello_v2`.`users`.`id` = NULL LIMIT 1
   ActiveRecord::RecordNotFound: Couldn't find User with 'id'=1 [WHERE `intello_v2`.`users`.`deleted_at` IS NULL]
   from /Users/coats/.rvm/gems/ruby-3.1.2/gems/activerecord- 
   6.1.6.1/lib/active_record/relation/finder_methods.rb:357:in 
   `raise_record_not_found_exception!'

当试图获取ID为1但活动记录的用户时,查询将ID 1替换为NULL并返回错误。
它需要ID为1的User行。
宝石我们正在使用的gollowing

Gems included by the bundle:

actioncable (6.0.6.1)
actionmailbox (6.0.6.1)
actionmailer (6.0.6.1)
actionpack (6.0.6.1)
actiontext (6.0.6.1)
actionview (6.0.6.1)
active_model_serializers (0.10.13)
activejob (6.0.6.1)
activemodel (6.0.6.1)
activerecord (6.0.6.1)
activerecord-import (1.4.1)
activerecord-session_store (2.0.0)
activestorage (6.0.6.1)
activesupport (6.0.6.1)
acts_as_list (1.0.4)
addressable (2.8.1)
airbrake (13.0.3)
airbrake-ruby (6.2.0)
apartment (2.2.1 influitive/apartment@f266f73)
ast (2.4.2)
autoprefixer-rails (10.4.7.0)
aws-eventstream (1.2.0)
aws-partitions (1.678.0)
aws-sdk-core (3.169.0)
aws-sdk-kms (1.62.0)
aws-sdk-s3 (1.118.0)
aws-sigv4 (1.5.2)
bcrypt (3.1.18)
bindex (0.8.1)
bootstrap (4.0.0)
bootstrap-datepicker-rails (1.9.0.1)
bootstrap-select-rails (1.13.8)
builder (3.2.4)
bundler (2.3.17)
byebug (11.1.3)
case_transform (0.2)
chartkick (5.0.1)
childprocess (4.1.0)
ci_reporter (2.0.0)
ci_reporter_rspec (1.0.0)
climate_control (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.2.0)
connection_pool (2.3.0)
content_disposition (1.0.0)
counter_culture (3.3.0)
crack (0.4.5)
crass (1.0.6)
database_cleaner (2.0.1)
database_cleaner-active_record (2.0.1)
database_cleaner-core (2.0.1)
date (3.3.1)
devise (4.8.1)
devise-security (0.17.0)
devise_invitable (2.0.7)
diff-lcs (1.5.0)
docile (1.4.0)
dotenv (2.8.1)
dotenv-rails (2.8.1)
down (5.4.0)
erubi (1.12.0)
execjs (2.8.1)
factory_bot (6.2.1)
factory_bot_rails (6.2.0)
ffi (1.14.2)
flag-icons-rails (3.4.6.1)
font-awesome-sass (4.7.0)
globalid (1.0.1)
groupdate (6.1.0)
hashdiff (1.0.1)
httparty (0.21.0)
i18n (1.12.0)
iniparse (1.5.0)
intellocompute (0.1.0 a6be71c)
interception (0.5)
jmespath (1.6.2)
jquery-fileupload-rails (1.0.0)
jquery-rails (4.5.1)
jquery-sparkline-rails (2.1.1 c5b531f)
jquery-ui-rails (6.0.1)
json (2.6.3)
jsonapi-renderer (0.2.2)
jwt (2.6.0)
kaminari (1.2.2)
kaminari-actionview (1.2.2)
kaminari-activerecord (1.2.2)
kaminari-core (1.2.2)
local_time (2.1.0)
lograge (0.12.0)
logstash-event (1.2.02)
logstash-logger (0.26.1)
loofah (2.19.1)
mail (2.8.0.1)
marcel (1.0.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (3.2022.0105)
mimemagic (0.3.10)
mini_mime (1.1.2)
minitest (5.17.0)
multi_json (1.15.0)
multi_xml (0.6.0)
mustermann (3.0.0)
mysql2 (0.5.5)
net-imap (0.3.4)
net-pop (0.1.2)
net-protocol (0.2.1)
net-smtp (0.3.3)
nio4r (2.5.8)
nokogiri (1.14.0)
orm_adapter (0.5.0)
overcommit (0.60.0)
pace-rails (0.1.3)
paperclip (6.1.0)
parallel (1.22.1)
paranoia (2.6.1)
parser (3.2.0.0)
popper_js (1.16.1)
pretender (0.4.0)
pry (0.14.2)
pry-byebug (3.10.1)
pry-doc (1.4.0)
pry-rails (0.3.9)
pry-rescue (1.5.2)
psych (3.3.4)
public_suffix (5.0.1)
puma (5.6.5)
puma-daemon (0.1.2)
racc (1.6.2)
rack (2.2.6.2)
rack-protection (3.0.4)
rack-test (2.0.2)
rails (6.0.6.1)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.5.0)
rails-i18n (7.0.6)
railties (6.0.6.1)
rainbow (3.1.1)
rake (13.0.6)
ransack (3.1.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
rbtree3 (0.7.0)
recaptcha (5.12.3)
redis (4.5.1)
regexp_parser (2.6.2)
request_store (1.5.1)
responders (3.0.1)
rexml (3.2.5)
ros-apartment (2.3.0)
rspec (3.12.0)
rspec-core (3.12.0)
rspec-expectations (3.12.2)
rspec-mocks (3.12.3)
rspec-rails (5.1.2)
rspec-sidekiq (3.1.0)
rspec-support (3.12.0)
rspec_junit_formatter (0.6.0)
rubocop (1.44.0)
rubocop-ast (1.24.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
ruby_http_client (3.5.5)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (4.0.0)
sass-rails (6.0.0)
sassc (2.4.0)
sassc-rails (2.1.2)
sendgrid-actionmailer (3.2.0)
sendgrid-ruby (6.6.2)
sentry-rails (5.7.0)
sentry-ruby (5.7.0)
shrine (3.4.0)
sidekiq (5.2.10)
simplecov (0.22.0)
simplecov-cobertura (2.1.0)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sinatra (3.0.4)
slim (5.0.0)
sprockets (4.2.0)
sprockets-rails (3.2.2)
temple (0.10.0)
terrapin (0.6.0)
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.0.11)
timeout (0.3.1)
to_bool (2.0.0)
tzinfo (1.2.10)
uglifier (4.2.0)
unicode-display_width (2.4.2)
vcr (6.1.0)
warden (1.2.9)
web-console (4.2.0)
webmock (3.18.1)
webrick (1.7.0)
websocket-driver (0.7.5)
websocket-extensions (0.1.5)
write_xlsx (1.09.5)
yard (0.9.28)
zeitwerk (2.6.6)
a0zr77ik

a0zr77ik1#

如果你有一个default_scope { where id: nil },你所展示的行为就会发生,虽然我不知道这是如何发生的,但你确实有paranoia,它会为你设置为a_a_p的任何模型添加一个默认范围。
不推荐使用paranoia,README只引用了Rails 5之前的版本,这意味着您不应该使用它。
现在,这是否是设置这个default_scope的原因还不清楚,尽管我刚才说了关于那个宝石的事情,但对我来说似乎真的很奇怪,所以也许是别的东西-但我会从那里开始。

相关问题