i have iteration
current_item = line_items.create(product_id: product_id, instruction: instruction) current_item.save attribute_values.each |attribute| current_item.line_item_attributes.create(product_attribute_id: attribute) end and gives me error on creating attributes. when print out current_item
#<lineitem id: nil, product_id: 1, cart_id: 36, created_at: nil, updated_at: nil, quantity: 1, instruction: "", order_id: nil> which understanding means it's not saved yet. how can fix this?
after calling create! error returned is:
validation failed: order must exist the order model added migration:
class addordertolineitem < activerecord::migration[5.0] def change add_reference :line_items, :order, index: true, foreign_key: true end end and lineitem belongs_to :order. issue here want blank, because in case doesn't belong order yet.
Comments
Post a Comment