I have
Product model
has_many :licence_products, dependent:
:nullify
has_many :licences, through: :licence_products
Licence model
has_many :licence_products, autosave: true,
dependent: :destroy
has_many :products, through: :licence_products
LicenceProduct model
belongs_to :licence
belongs_to :product
NOw when I delete a product, I want to update the product_id of licence_products table to nill, where (licence_status = draft)
status is in licence tables, product_id is in licence_products table
Product where @draft_licence= product.licences.status == draft , update @draft_licence.licence_products.product_id = nill.
I am not able to update the query . How can I do this?
authorize @product
if(@product.licences.present?)
@licences_draft = @product.licences.where(:aasm => "Draft").all
if(@licences_draft.exists?)
@licences_draft.licence_products.update_all(:product_id => nil)
end