Skip to content

Commit

Permalink
Fix(Promotions): Instantiate single promo code with promotion
Browse files Browse the repository at this point in the history
Because promotion codes have the `-> {with_discarded}` scope on the
`promotion` association, a promo code that's instantiated with
`promotion.codes.new` will not have the promotion associated at the
beginning, leading to errors. This passes in the promotion so that the
promo code knows where it belongs.
  • Loading branch information
mamhoff committed Nov 18, 2024
1 parent 7d86a96 commit 405ebb0
Showing 1 changed file with 1 addition and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class PromotionsController < BaseController

def create
@promotion = model_class.new(permitted_resource_params)
@promotion.codes.new(value: params[:single_code]) if params[:single_code].present?

@promotion.codes.new(promotion: @promotion, value: params[:single_code]) if params[:single_code].present?
if params[:code_batch]
@code_batch = @promotion.code_batches.new(code_batch_params)
end
Expand Down

0 comments on commit 405ebb0

Please sign in to comment.