I am setting up Core Data in my app programmatically, and have come across an "issue" (not exactly an issue, but was wondering if anyone had found a nice way around it).
I have a base class FormElement
(which extends NSManagedObject
). I then extend this for various form types, e.g. TextFieldFormElement
, TextAreaFormElement
and SwitchFormElement
, all extend FormElement
. I also have a FileAsset
class (which extends NSManagedObject
) that stores information about files. TextFieldFormElement
and TextAreaFormElement
have a to-many relationship with FileAsset
but SwitchFormElement
does not.
I understand that I don't HAVE to sent an inverse relationship for FileAsset
, or that I could set multiple properties in FileAsset
as the inverse for each FormElement
that can have a relationship with FileAsset
(e.g. FileAsset.textFieldElement
, FileAsset.textAreaElement
etc).
My question is: has anyone found a nice workable solution for allowing an inverse relationship with any managed object of a certain type? What I really want to do is simply have one property in FileAsset
(e.g. FileAsset.element
) that will take any object of type FormElement
(and so, any object that extends FormElement
)?
Programmatically I can't see an obvious was to achieve this:
TextFieldFormElement >(one-to-many)> FileAsset
TextAreaFormElement >(one-to-many)> FileAsset
FileAsset >(one-to-one)> FormElement
Has anyone ran in to a problem like this before and found a nice solution? I guess my other option would be to ensure FormElement
simply encompasses all possible properties for a form element and do-away with extending FormElement
.
Many thanks!