small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
15 Sep 2009, 23:57
Karl Goiser (6 posts)

Hello,

Lots of models and descriptions talk about the inverse relationship with the idea that two entities are related in both directions.

What about where you have an entity that you want to share across multiple other entities. For example, you might have a documents model with title, heading, chapter, paragraph entities, each possibly having 0 to many images associated with them.

In this case, you’d want to share an image entity across all the other entities. That is, the title, heading, chapter and paragraph entities would all have to-many relationships with the image entity.

How do you do the inverse in this situation?

Thanks in advance,

Karl

Avatarsmall_pragsmall
20 Sep 2009, 14:55
Marcus S. Zarra (284 posts)

In that situation you would set up the relationship with a very simple abstract parent entity which holds the reverse relationship and have all of your objects that want to relate to the image extend from that abstract parent.

Generic-user-small
21 Sep 2009, 20:25
Karl Goiser (6 posts)

Thanks for the reply, Marcus!

The “Entity Inheritance” section of your book points out that this is not such a good idea. Looks like I’ll have to stick with multiple tables…

Regards,

Karl

Avatarsmall_pragsmall
22 Sep 2009, 14:47
Marcus S. Zarra (284 posts)

Depends on the situation. If the child tables are really wide and unique then probably not. If they are narrow or you can roll up several attributes to the parent table then it is definitely something that can be done. Personally I would draw it out and have Core data build a sqlite table for you then peek at the results and decide from there.

Generic-user-small
05 Oct 2009, 23:26
Karl Goiser (6 posts)

Thanks Marcus!

That’s great - and practical - stuff to think about.

Regards,

Karl

You must be logged in to comment