MagicalRecord how to add objects to relationships

in iOS5.0, using an arc, I use magic notation to create objects in the master data. I have a product object that is one to many related, called currentPromotions, with Promotion objects. The Promotion object also has a parentProduct feedback. I can create these objects, but I do not agree on how to create relationships and attach Promotion objects to the product using MagicalRecord on github.

Also, the magic record documentation is too scarce. any pointers to this will also be helpful.

Thanks in advance for your help.

+4
source share
1 answer

Most of the baseline information is used when using MagicalRecord. I suggest looking there when you are looking for documentation. MagicalRecord is basically trying to codify what the documents tell you. This is a good idea.

For your problem, however, it seems like you have this relationship:

Product <---> Promotion 

You bind your two instances as follows:

 Product *a = //...; a.promotion = [Promotion createEntity]; 

Everything else is done for you, not MagicalRecord, but Core Data. If you want to add a product to your collection of products for promotion, you can do:

 Promotion *p = //...; [p addProductOjbect:[Product createEntity]]; 

The addProductObject: method is created at runtime by Core Data.

I highly recommend that you learn more about Core Data when viewing MagicalRecord, as MagicalRecord does not hide anything. It just makes β€œeasy” things simple and difficult.

+8
source

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


All Articles