0
votes

I have product, feature, product_feature, and quota.

# product.rb

  has_many :product_features, dependent: :destroy
  has_many :quotas, through: :product_features
  has_many :features, through: :product_features

  accepts_nested_attributes_for :product_features
# product_feature.rb

  belongs_to :product
  belongs_to :feature
  has_one :quota, dependent: :destroy

  accepts_nested_attributes_for :feature
# quota.rb

  belongs_to :product_feature
# feature.rb

  has_many :product_features, dependent: :destroy
  has_many :quotas, through: :product_features
  has_many :products, through: :product_features

I'm trying to add quota into the nested attributes to allow a POST to product, to create product, features, product_features, and quotas all in one go.

Right now, my product_params method looks like:

      def product_params
        params.require(:product).permit(:name, :status, :description,
                                        product_features_attributes: [{ feature_attributes: %i[name company_id] }])

How do I add quotas into this complex nested attributes?

Quota belongs_to product_feature, so a product_feature must be created for a quota to be created. That leads me to believe quota should accept nested attributes for product_feature. However, not every product_feature will have a quota, so i'm not sure how that would work.