我正在使用Rails 5.0.2運行counter_culture
gem,v1.6.2(對於我當前不能升級到1.7)。我有一個Contact
,ContactGroup
和Group
模型,就像這樣:ArgumentError:方法.group()必須包含參數
class Contact < ApplicationRecord
has_many :contact_groups
has_many :groups, through: :contact_groups
counter_culture [:contact_groups, :group], touch: true
counter_culture [:contact_groups, :group],
column_name: :confirmed_count,
column_names: { ["contacts.confirmed_at IS NOT NULL"] => 'confirmed_count' },
touch: true
end
class ContactGroup < ApplicationRecord
belongs_to :contact
belongs_to :group
validates_uniqueness_of :contact_id, scope: :group_id
end
class Group < ApplicationRecord
has_many :contact_groups
has_many :contacts, through: :contact_groups
end
從我從閱讀的文檔明白,這種設置是正確的。如果我運行Contact.counter_culture_fix_counts
,一切工作正常。如果我嘗試創建新聯繫人,如下所示,我收到以下錯誤消息。
c = Contact.new(attrs)
[9] pry(main)> #<Contact id: nil, first_name: "Billy", last_name: "The Kid", email: "[email protected]" ...>
c.valid?
[10] pry(main)> true
c.save
[11] pry(main)> c.save
(0.2ms) BEGIN
Contact Exists (0.5ms) SELECT 1 AS one FROM "contacts" WHERE "contacts"."email" = '[email protected]' LIMIT 1
Contact Exists (0.5ms) SELECT 1 AS one FROM "contacts" WHERE "contacts"."email" = '[email protected]' AND "contacts"."company_id" = 94 LIMIT 1
Contact Exists (0.6ms) SELECT 1 AS one FROM "contacts" WHERE "contacts"."preferences_token" = '6dc8b7943f87efd81477450c199e6ecf' LIMIT 1
SQL (1.2ms) INSERT INTO "contacts" ("first_name", "last_name", "email", "created_at", "updated_at", "company_id", "color", "encrypted_password", "confirmation_token", "confirmation_sent_at", "unconfirmed_email", "request_email_frequency", "invite_email_sent_at", "preferences_token", "key") VALUES ('Billy', 'The Kid', '[email protected]', '2017-07-20 18:24:16.880278', '2017-07-20 18:24:16.880278', 94, '#344B59', '$2a$10$baAhoJtROfmJRx1ymb7aX.5s/5u.99..fT9OsC9MvoKEpmT4olq.G', '6dc8b7943f87efd81477450c199e6ecf', '2017-07-20 17:50:50.005270', '[email protected]', 'Daily', '2017-07-20 17:50:50.033649', '6dc8b7943f87efd81477450c199e6ecf', 'Billy-dedf62') RETURNING "id"
(0.3ms) ROLLBACK
ArgumentError: The method .group() must contain arguments.
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/query_methods.rb:1214:in `check_if_method_has_arguments!'
我一直在努力弄清楚是什麼導致這一段時間,至今我唯一的工作原理是,有一個名稱衝突與我的模型Group
和ActiveRecord的的.group()
方法。我正在考慮將Group
重命名爲其他內容,但這顯然是很多工作,所以我想首先查明我的理論是否正確,如果可能的話。思考?
這是我懷疑不幸的。我建立了一個新的分支,並將我的'Group'模型改爲'Team',這足以解決這個問題。謝謝! – ACIDSTEALTH