Ruby on rails 无法修改关联';一些型号';因为它经历了不止一个关联

Ruby on rails 无法修改关联';一些型号';因为它经历了不止一个关联,ruby-on-rails,rails-admin,Ruby On Rails,Rails Admin,我在尝试创建/编辑包含几个“has_many…through”元素的实例时出错。我一直在寻找解决方法,我尝试在一些和所有关系上添加“,:autosave=>false”,但似乎没有任何效果 ActiveRecord::HasManyThroughNestedAssociationsAreReadonly at /customer/new Cannot modify association 'Customer#shops' because it goes through more than on

我在尝试创建/编辑包含几个“has_many…through”元素的实例时出错。我一直在寻找解决方法,我尝试在一些和所有关系上添加“,:autosave=>false”,但似乎没有任何效果

ActiveRecord::HasManyThroughNestedAssociationsAreReadonly at /customer/new

Cannot modify association 'Customer#shops' because it goes through more than one other
association.
这是我要创建/编辑的
客户
模型:

class Customer < ActiveRecord::Base
  belongs_to :user
  has_many :customer_shop_groups
  has_many :shop_groups, -> { order(:name) }, through: :customer_shop_groups
  has_many :shops, -> { order(:name) }, through: :shop_groups
  has_one  :api_consumer
end
这是我的
ShopGroup
型号:

class CustomerShopGroup < ActiveRecord::Base
  belongs_to :customer
  belongs_to :shop_group
  has_many :shops, through: :shop_group
end
class ShopGroup < ActiveRecord::Base
  has_many :shops
  has_many :customer_shop_groups
  has_many :customers, through: :customer_shop_groups
  has_many :shop_group_maps, -> { order 'level' }, class_name: 'Map'
  has_many :heatmaps, through: :shop_group_maps
  scope :with_friendly_id, lambda { |friendly_id| where(friendly_id: friendly_id) }
end
class ApiConsumer < ActiveRecord::Base
  belongs_to :customer
  has_many :shops, through: :customer
end

看起来你试图以客户的形式拯救商店,但这是行不通的。一种方法是通过::shop\u groups替换
has\u many:shops,->{order(:name)},创建一个
has\u和\u属于\u many
关联

谢谢你的帮助,但这不是我想要做的。商店可能属于一个或多个客户,但也可能属于一个或多个购物组。ShopGroup还用于命名一组店铺,模拟特定的层次结构。