ruby on rails - Cannot modify association 'SomeModels' because it goes through more than one other association -
i getting error when trying create/edit instance has few "has_many ... through" elements. have been looking workaround, have tried add together ", :autosave => false" on few , on relations nil seems work.
activerecord::hasmanythroughnestedassociationsarereadonly @ /customer/new cannot modify association 'customer#shops' because goes through more 1 other association.
this customer
model 1 want create/edit:
class client < 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
and these models have 'has_many...through' dependencies :
this customershopgroup
model:
class customershopgroup < activerecord::base belongs_to :customer belongs_to :shop_group has_many :shops, through: :shop_group end
this shopgroup
model:
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
and apiconsumer
model:
class apiconsumer < activerecord::base belongs_to :customer has_many :shops, through: :customer end
it seems you're trying save shops in client form, not work. 1 way replacing has_many :shops, -> { order(:name) }, through: :shop_groups
creating has_and_belongs_to_many
association.
ruby-on-rails rails-admin
No comments:
Post a Comment