0

In my model I have: Product <<---> Order

Product Attributes: productName productPrice Product Relationships: order

Order Attributes: orderName salePerson Order Relationships: products

Imagine I have a Product (call it product1): productName: MacBook productPrice: 1200

The application in general used to sale products. So after add and done the sale. Automatically create an Order (call it currentOrder) which contain product1.

[currentOrder addProductsObject:product1];

Next I changed product1 price to: productPrice: 1000

After I recheck the product inside the currentOrder, I'll see the productPrice is UPDATED to: 1000 Which I need to not change and still be exactly like the previous (1200).

Basically I would to do something do NOT update the previous object.

Alish
  • 133
  • 3
  • 13
  • 1
    Still it is not clear. What are you trying to achieve? You've updated property and you see result. What is wrong here? – Mark Kryzhanouski Feb 18 '13 at 13:15
  • product1 their price used to 1200. After I change the product1 the new price which 1000 effect the previous data which I don't want to effect that. – Alish Feb 18 '13 at 13:57
  • If you want to discard your latest changes just refresh produst1 [context refreshObject:product1 mergeChanges:NO] – Mark Kryzhanouski Feb 18 '13 at 14:03
  • Thanks for your comment. I think I couldn't explain my issue very well. 1- create order1 with product1 price 1200. 2- change product1 price to 1000. 3- create order2 with product1 price 1000. Now I want to have: order1 product1 price be 1200 and order2 product1 price be 1000 – Alish Feb 18 '13 at 14:28
  • You have to create a different object `product2` for `order2`. – Martin R Feb 18 '13 at 14:52
  • 2
    oh I understand you. Your business model is not suitable for your case. You need to have another entity 'Sale' or so. Your model should look like: Order <--->>Sale, Product <---> Sale. Product Attributes: productName. Order Attributes: orderName salePerson Order Relationships: sales. Save Attributes: productPrice Sale Relationships: order. So in this way you decouple price from product and will be able store different prices in different orders. – Mark Kryzhanouski Feb 18 '13 at 14:54
  • Thanks. I think you are right. I though maybe not need that Sale. But you are saying in need that. Anyway thanks for your comment. – Alish Feb 18 '13 at 15:02
  • @MarkKryzhanouski: Yes, I just thought of the same solution. Why don't you post this as an answer? (Perhaps it should be Product <-->> Sale, otherwise each product can be sold only once!) – Martin R Feb 18 '13 at 15:04

1 Answers1

3

Your business model is not suitable for your case. You need to have another entity 'Sale' or so. Your model should look like: Order <--->>Sale, Product <---> Sale. Product Attributes: productName. Order Attributes: orderName salePerson Order Relationships: sales. Save Attributes: productPrice Sale Relationships: order. So in this way you decouple price from product and will be able store different prices in different orders.

Mark Kryzhanouski
  • 7,251
  • 2
  • 22
  • 22