我的模型架构:
用户
has_many :activities
has_many :companies through: :activities
公司
has_many :activities
has_many :users, through: :activities
活动
belongs_to :user
belongs_to :company
当我尝试运行current_user.activities.delete_all(["company_id=?", params[:id]])
或clear
或destroy
时出现问题我收到此错误:
ArgumentError: wrong number of arguments (1 for 0)
from /home/rom/.rvm/gems/ruby-1.9.3-p194@rails-3.2.8/gems/activerecord-3.2.8/lib/active_record/associations/collection_association.rb:156:in `delete_all'
from /home/rom/.rvm/gems/ruby-1.9.3-p194@rails-3.2.8/gems/activerecord-3.2.8/lib/active_record/associations/collection_proxy.rb:46:in `delete_all'
答案 0 :(得分:1)
使用以下
Activity.delete_all(["company_id=? AND user_id=?", params[:id], current_user.id])