in iOS5.0, using arc, i'm using Magical record to create objects in core data. I have a product object that has a one to many relationship called 'currentPromotions' with Promotion objects. Promotion object has an inverse relationship 'parentProduct', too. I am able to create these objects, but am stymied at how to create the relationship and attach the Promotion objects to the product using MagicalRecord in github.
Also the documentation on magical record is too sparse. any pointers on this will also be helpful.
Thanks in advance for your help on this
Most information on Core Data applies when using MagicalRecord. I suggest looking there first when looking for documentation. MagicalRecord basically tries to codify what the docs tell you is a good idea.
For your problem though, it seems that you have a relationship like this:
Product <---> Promotion
You connect your two instances like this:
Product *a = //...;
a.promotion = [Promotion createEntity];
Everything else is done for you, not by MagicalRecord, but Core Data. If you want to add a product to your collection of products for a promotion, you can do:
Promotion *p = //...;
[p addProductOjbect:[Product createEntity]];
The addProductObject:
method is created for you at runtime by Core Data.
I highly suggest that you learn more about Core Data when looking into MagicalRecord, since MagicalRecord does not really hide anything. It just makes the "easy" stuff simple, and the hard stuff possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With