composite-primary-keys / composite_primary_keys

Composite Primary Keys support for Active Record
1.03k stars 350 forks source link

Getting Error when I try to delete_all data in batch #566

Closed pranjal0819 closed 2 years ago

pranjal0819 commented 2 years ago

When i try to delete data in batch using limit() it throw NoMethodError error

2.6.6 :004 > Account.all.limit(10).delete_all
D, [2021-11-15T15:31:41.424603 #34867] DEBUG -- :    (0.4ms)  SET NAMES utf8 COLLATE utf8_general_ci,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483

Traceback (most recent call last):
/home/shadow/.rvm/gems/ruby-2.6.6@default/gems/composite_primary_keys-11.3.1/lib/composite_primary_keys
/connection_adapters/abstract_mysql_adapter.rb:14:in `block in subquery_for': undefined method `name' for ["currency_id", "member_id"]:CompositePrimaryKeys::CompositeKeys (NoMethodError)
cfis commented 2 years ago

Could you provide some more information? What is the definition of Account? What version of Rails? Also, please include a full traceback not just a couple lines.

pranjal0819 commented 2 years ago

Sure,

Account is the object of ActiveRecord::Base and Account has the primary key of member_id and currency_id. Ruby version: ruby-2.6.6 Rails version: 'rails', '~> 5.2.4.5'

"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/composite_primary_keys-11.3.1/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb:14:in `block in subquery_for'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/composite_primary_keys-11.3.1/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb:14:in `map'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/composite_primary_keys-11.3.1/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb:14:in `subquery_for'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/activerecord-5.2.4.5/lib/active_record/connection_adapters/abstract/database_statements.rb:423:in `join_to_update'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/composite_primary_keys-11.3.1/lib/composite_primary_keys/relation.rb:77:in `delete_all'",
"(irb):19:in `<main>'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/workspace.rb:116:in `eval'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/workspace.rb:116:in `evaluate'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/context.rb:450:in `evaluate'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:557:in `block (2 levels) in eval_input'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:741:in `signal_status'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:538:in `block in eval_input'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/ruby-lex.rb:237:in `block (2 levels) in each_top_level_statement'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/ruby-lex.rb:219:in `loop'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/ruby-lex.rb:219:in `block in each_top_level_statement'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/ruby-lex.rb:218:in `catch'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb/ruby-lex.rb:218:in `each_top_level_statement'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:537:in `eval_input'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:472:in `block in run'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:471:in `catch'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:471:in `run'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/irb-1.3.4/lib/irb.rb:400:in `start'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/railties-5.2.4.5/lib/rails/commands/console/console_command.rb:64:in `start'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/railties-5.2.4.5/lib/rails/commands/console/console_command.rb:19:in `start'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/railties-5.2.4.5/lib/rails/commands/console/console_command.rb:96:in `perform'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/railties-5.2.4.5/lib/rails/command/base.rb:69:in `perform'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/railties-5.2.4.5/lib/rails/command.rb:46:in `invoke'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/railties-5.2.4.5/lib/rails/commands.rb:18:in `<main>'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'",
"/home/shadow/.rvm/gems/ruby-2.6.6@peatio/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'",
"bin/rails:15:in `<main>'"

Project link: https://github.com/openware/peatio

cfis commented 2 years ago

Sorry for the late reply. So that's a pretty old version of Rails and CPK. Happy to take a patch if you'd like to send one in, but right now we are only supporting Rails 7 and 6.1.