Note that there are some explanatory texts on larger screens.

plurals
  1. POMagicalRecord import of polymorphic relationship
    primarykey
    data
    text
    <p>I using MagicalRecord to import data into a CoreData Model that makes heavy use of polymorphism.</p> <p>For example, a set of concrete entities all extending the same abstract entity, are used in a many-to-many relationship from another class, which has it's property type specified in the model as being of the Abstract class type, allowing the Set to be be a mixture of both concrete types. </p> <p>MagicalRecord does not generate the correct sub entities from the imported data.</p> <p>Here is an example of the <em>simplest</em> case.</p> <p>I have an entity called <code>PlantName</code> which has a <code>names</code> Set defined as type <code>NameComponent</code>. I have an Abstract Entity <code>NameComponent</code> which has: <code>searchString</code>, <code>timeStamp</code> and <code>title</code>. It is extended by two sub entities : <code>CommonName</code> which has <code>locale</code> and <code>LatinName</code> which has <code>type</code>.</p> <p>The relevant snippet of JSON to be imported :</p> <pre><code>"names": [ /* NameComponent(s) */ {"title": "Jade Plant", "locale": "en_us"}, /* CommonName - US English */ {"title": "Crassulaceae", "type":4}, /* LatinName - Family */ {"title": "Crassula", "type":5}, /* LatinName - Genus */ {"title": "Ovata", "type":6} /* LatinName - Species */ ] </code></pre> <p>After the import runs, if I look in the SQLite DB, I find all of the records have been imported as the abstract class type, furthermore, all of the attributes unique to each concrete class type are missing.</p> <p>The only place where I can find an example of this working is in the Unit Tests for MagicalRecord. However, even that is different in one important place. The test relationships are concretely typed, whereas mine are typed by the abstract class.</p> <p>I assume this difference is what is causing MagicalRecord to not generate the individual records as concrete classes.</p> <p>Is there a way to resolve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload