Feedback Warning - Ask for Inverse Relationship Practices

I have an Order table that contains information about a specific order (when it starts, how many people, etc.), and that the Order table has a To-Many relation to the Item Item table. I call it the relation "orderItems".

The compiler gives me a warning: "The Order.orderedItems-to-many relationship does not have the opposite: it is an advanced parameter (no object can be in multiple destinations for a specific relationship)"

How do you usually do for feedback? Do I need to create new relationships in a menu item in order to return to order and establish an inverse relationship to โ€œordered itemsโ€? (In fact, there is no reason to save this data in the menu table)

Someone can explain to me why, or at least tell me the reason why I need to create feedback in the Item Menu table.

Thanks in advance,

+4
source share
2 answers

I ran into this warning and problem! Here is what you need to know ...

Let's say you have two tables - Cars and Drivers. You define a one-to-one relationship - one car to one driver, but not the opposite.

So, if you create a car and assign a driver to it, if you delete the driver later, and then try and get access to car.driver, your program will fail. Car.driver will not be nil - this will cause your program to crash.

So, if you do not create an inversion, you can never check if there is something, and you canโ€™t even work without problems with car.driver in general if the driver has been removed.

I don't like how Xcode has this setting. It should invert by default and be a pain in the ass to change it.

Inversion setup is simple. Just open your xcdatamodel in Xcode, click on the existing ratio and check the reverse field.

+18
source

Usually you should always add inverse relationships.

Do not think about Core Data in terms of the tables that will be generated. In fact, Core Data is smart enough not to put data in multiple tables.

Focus on developing a data model that will meet your needs (and add inverse relationships).

+4
source

Source: https://habr.com/ru/post/1300304/


All Articles