Re: Converting database to Core Data
Re: Converting database to Core Data
- Subject: Re: Converting database to Core Data
- From: Keary Suska <email@hidden>
- Date: Thu, 10 Jul 2014 16:19:57 -0600
On Jul 10, 2014, at 2:00 PM, William Squires wrote:
> I'm trying to convert the following. I have two tables in a database, "TransactionEntry", and "ReasonCode". A "TransactionEntry" record is just a posting from a POS (Point-of-Sale) terminal, and has these fields (of interest):
>
> Table (TransactionEntry)
> ID As Int32
> PrimaryReasonCode As Int32 // both of these link to <ReasonCode>.ID
> SecondaryReasonCode As Int32
> ...
>
> and a "ReasonCode" record is used when a certain types of transactions occur, such as POSItemReturned, POSItemVoided, POSCommError, and a few others.
>
> Table (ReasonCode)
> ID As Int32
> Description As Varchar(50)
> ReasonCode As Int16 // just an enum
> ...
>
> All would be good and well if the TransactionEntry table had only one reference (.PrimaryReasonCode) to the ReasonCode table, but some transactions (such as a voided item) require the manager to fill in both the primary and secondary reason codes. I can create the entities, and replace the Int32 record numbers/IDs with a relationship.
> I create the relationship in entity "TransactionEntry" and set it to "ReasonCode", leaving the inverse relationship to "none" for now. I then create an inverse relationship in entity "ReasonCode" to refer back to "TransactionEntry". Now I can create the inverse relationships in both directions. 1:1 for TransactionEntry -> ReasonCode, and 1:many for ReasonCode -> TransactionEntry. All okay so far.
> Primary ReasonCode records (entities) are re-used to save memory, and the .Description fields are pre-set to values such as, "return item", "wrong key hit", "cc reader not working", etc... Secondary ReasonCode entities are (usually) created on-demand from the POS terminal when the manager logs in. A few are re-used, but mostly new entities are created. The problem now comes when I try to create the same relationships from TransactionEntry entities to ReasonCode entities for the secondary reason code records (entities), since it won't let me make both inverse relationships 1:many from ReasonCode back to TransactionEntry.
> Is this a limitation of CoreData? Or is there a way around this? Can I ignore Xcode's warnings about not having inverse relationships, and simply set the inverse relationships from the TransactionEntry entity(ies) to the ReasonCode Entity to "none", and simply get rid of the inverse relationships in the ReasonCode entity?
It's a limitation of Core Data. The solution is to use an intermediary entity, similar to a many-to-many relationship implementation. I would highly recommend this, as one-way relationships are fragile and prone to error.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden