DmitryTsepelev / store_model

Work with JSON-backed attributes as ActiveRecord-ish models
MIT License
1.04k stars 85 forks source link

fix: Add _destroy attr_accessor for association in nested attributes #139

Closed mateusnava closed 1 year ago

mateusnava commented 1 year ago

This is an improvement for this PR.

The idea here is to automatically adds _destroy attribute in the association class when allow_destroy is true.

Example

class Requirement
  attribute :categories, Category.to_array_type
  accepts_nested_attributes_for [:categories, { allow_destroy: true }]
end

Without this PR

class Category
  include StoreModel::Model

  attr_accessor :_destroy
end

With this PR

class Category
  include StoreModel::Model
end