litov
litov

Reputation: 540

can a relationship in core data link an instance of an entity twice to another instance

I want to make a to-many relationship that can save an instance of an entity more than ones.

for exemple, lets say I have two entities: buyer, product. now I have a buyer "jon", and a product "tomato", jon should be able to have more then 1 tomato.

another solution may be to save a counter somewhere, but i cant find an efficient way to do so.

Upvotes: 0

Views: 142

Answers (1)

Caleb
Caleb

Reputation: 125007

Two ways to do that, depending on your needs:

  • Create a different object for each individual tomato, so that you're modeling every tomato anyone ever purchases. This probably isn't a great strategy for tomatoes, where you don't care much about the individual objects, but it could be a good plan for cars, where each vehicle is unique and should be tracked separately.

  • Create an entity that represents a purchase transaction. Jon isn't buying the same tomato several times, he's buying some tomato several times. The thing you want to track isn't the tomato but the purchase.

Upvotes: 2

Related Questions