Core Data does not use my Mapping Model - core-data

When I set the option 'NSInferMappingModelAutomaticallyOption' to yes, the new model is setup using the old models data. However, it should be using my custom Mapping Model to update specific values.
For some reason it does not use this mapping model and I really need it to as some important data is not moved from one old entity to a new entity.
Any ideas?

Related

Synchronization between code and model in Visual Paradigm

I create a class diagram and then generate their code by Visual Paradigm.
I have inserted a lot of code into generated classes and now I need to update the model. but I would like to perform updating through Visual Paradigm for easiness.
if I update my model and then generate classes and replace them on current classes I will lose my codes.
how could I insert my code in the model to keep and maintain them after generating classes code in the model?
I could update classes and then update the model by them, but updating in the model is more simple and I want to update my model first and then update my classes based on new model and keep classes implementation codes as well.
solved :
in roundtrip, changes will be merged(not overwrites) and codes in the class file will be maintained. so I should update the model and start roundtrip on the existing file to merge new model element in the existing model element and codes.
You want to update your model to reflect the changes done in the sources, that means update classes already defined in your model, add new classes in sources not yet defined in your model, delete classes existing in the model but not anymore present in the sources.
All of that is a "roundtrip" (from sources), which must not be confused with the "reverse" (from sources) which does not update elements in the model but creates elements without considering the fact they already exist or not in the model.
It seems you can do that in Visual Paradigm (even the way to do seems strange for me because starting by a reverse) :
for Java (https://www.visual-paradigm.com/support/documents/vpuserguide/276/381/7530_generateorup.html)
for C++ ( https://www.visual-paradigm.com/support/documents/vpuserguide/276/501/28170_generateorup.html)
I encourage you to learn how to do using a new dedicated model / sources just made for that purpose, to not take the risk to destruct your existing model/sources by error

Does adding a Transient Property to a Core Data Entity require a new version model?

I have an existing data model with already existing entities. I would like to add a new property to an entity without changing the the core data model version. Can this be done by a Transient Property, since Transient Properties are never actually saved to the DB table?
Can't find any documentation on this.
After some researching this and many personal trials, it seems like adding a Transient Property does not require you to create a new version of the model

Creating through model relation not creating relation

I'm trying to create a relation between models using Loopback, but for some reason it seems like it is not saving my relations at all. But it could also be that I'm doing something wrong.
The relation looks like this:
So a User can be in 0 or more Pools. When they are in a Pool they are a PoolMember. And a PoolMember can add Predictions.
Right now I'm trying to create a relation between a User and Pools.
I did a slc loopback:relation and then selected User as from model. Then selected hasMany and picked Pool from the list. Then it asked if the relation has a throughModel. I selected Yes and then picked PoolMember from the list.
I'd then expect that either PoolMember.json or Pool.json has a relation defined in it. But they seem to remain unchanged.
I even deleted my project and redid everything. But have the same problem.
So am I doing something wrong here? Or is this a bug in Loopback?
If you are using built-in models ("User" in your case), you should extend built-in model and then create relation or any other modification.
Currently you cannot modify a built-in model's required properties. If you need to do this, then create your own custom model as a replacement instead.
By default, a LoopBack application has a built-in User model defined by user.json (this file is part of the LoopBack framework. Don't modify it; rather, follow the procedure in Extending built-in models).
See Customizing models and Managing users

Core data mapping model with new (non-optional) relationship

My original data model has an entity "Game". I have now updated the model to include an entity, "Match", which can refer to multiple games. I wish to add a Match to all of my old Games, and ideally this would be a non-optional relationship.
Currently I am setting Match to be optional, and simply adding a Match to every old Game in application:didFinishLaunching after the model has been updated. This works, but I'm wondering if this is really the best way to do it.
I have tried to follow the tutorial here, but I am getting stuck on the part with "StepOneEntityMigrationPolicy.m". I have created an NSEntityMigrationPolicy subclass and set it in the mapping model. I've tried overriding both createDestinationInstancesForSourceInstance and createRelationshipsForDestinationInstance:, but neither get called.
Is this perhaps because my Source and Destination are both the same (GameToGame)? Also, is there any benefit to doing this via the mapping model rather than as I am doing it now?
I think the simplest and most pragmatic way is what you are doing now, i.e. inserting the necessary new entities "manually" after an update. This is a common way to populate orphaned entities after a model version upgrade and perfectly fine.

CoreData Migration from one-to-many to many-to-many

I have a problem in upgrading an old data model to a current model. It has a couple of layers which could be causing the problem and I'm struggling to determine where the issue lies.
I have an abstract Client entity which contains generic relationships to phone numbers, email addresses, etc. In my old model there was a relationship where a client could own 1 Property (but a Property could have many owners) or a client could be a tenant in a Lease (but a Lease can have many tenants). I've now updated the model such that a Client can own many Properties and be part of many Leases.
The concrete Client entities basically add different naming information to the abstract so there are Individual, Business, Government and Import (imported from other systems) subclasses.
My expectation was that the one-to-many relationship established in the old data model would be added as a first instance in a new many-to-many relationship in the new data model. Unfortunately the upgraded data store doesn't appear to contain any relationships in the new concrete clients for Properties or Leases.
The old model:
Client{
Property<<-->Property.Owners
Tenancy<<-->Lease.Tenants
}
ImportClient:Client{
name:string
}
The new model:
Client{
Properties<<-->>Property.Owners
Tenancies<<-->>Lease.Tenants
}
ImportClient:Client{
name:string
}
So now for the possible problems I can see. Firstly the relationship names have changed in the Client entity from Property to Properties and from Lease to Leases. So I've added a mapping model. The model didn't automatically add an Entity Mapping for ClientToClient (only for the concrete classes) so I've tried adding one myself. I'm not sure however how to set up the Value Expression so at the moment it's:
FUNCTION($manager,"destinationInstancesForEntityMappingName:sourceInstances:","PropertyToProperty","$source.Property")
If I try and add the mapping to the concrete classes (so ImportClientToImportClient) it seems to be absolutely impossible to set the relationship values correctly (denied by the editor basically).
So my suspicions are that it's either failing to transfer the relationships because when the fetch is run against Client entity it returns nothing (whenever I've tried it this has been the case) or I'm just not getting the Value Expression right.
Help would be greatly appreciated because at the moment this is the only issue blocking the release of my major upgrade to the app.
So the solution as I've found it (for those who stumble across this later...) in general terms as I don't have time at present to detail all the code here.
Step 1: See if you can open your data store without any migration options. If that succeeds continue on, otherwise Step 2.
Step 2: Retrieve the store metadata with [NSPersistentStoreCoordinator metadataForPersistantStore...]
Step 3: Load your older models one at a time from most recent to oldest and use [NSManagedModel isConfiguration: compatibleWithStoreMetadata:] until you find a model that works
Step 4: Create a persistent store with the model that works and then create a managed object context from the data store and the persistent store
Step 5: Cache the failing relationship in a dictionary (I used pairs of UUIDs to identify the objects)
Step 6: Perform lightweight upgrade of the data store using your current managed object model
Step 7: Go through the dictionaries fetching the pairs of objects and associating them again
Yes you're going to have to use your own coding skills to implement this (it's about 250 lines of code for my instance) but hopefully this is the seed you need to get it working...

Resources