Reputation: 1737
I am new with Core Data and I experiment a design problem. Suppose I have two entities : "Product" and "Image".
The Image entity has an attribute named "type" ( normal, mini etc...).
I would like that the Product entity has attributes of type Image like : miniImageList, normalImageList etc... but I really don't know if it is possible given that with XCode4 graphical editor, it is not possible to create an attribute whose type is an entity previously declared.
The only ugly solution I found, is to create a to-many relation between Product and Image. Therefore, I have an NSSet generated which contains all the images I wish.The problem with this solution is that I need to test the type of the image I wish ( mini, normal ) etc... which is not really handy.
If any of you know how to solve this problem, you're really welcome ;)
Hope I've been clear, thank's for reading.
Upvotes: 0
Views: 147
Reputation: 6545
I would like that the Product entity has attributes of type Image like : miniImageList, normalImageList etc... but I really don't know if it is possible given that with XCode4 graphical editor, it is not possible to create an attribute whose type is an entity previously declared.
For that, you need to create relationships. An "attribute of type Image" is essentially a relationship between Product and Image.
A more appropriate solution in your case, would be to define fetched properties between Product and Image. Thus, miniImageList and normalImageList can be defined as fetched properties using the "filtering" you need to apply on your Images set. An important limitation of fetched properties though, is that they are not dynamic. You would need to ensure that the contents of the resulting Image NSArray take into consideration the latest Image entity additions/deletions/modifications.
Upvotes: 2
Reputation: 3253
Either seperate the different image sizes to entitys or you expand your Image entity to hold diferent sizes of the graphic.
Seccond method would be best in this case I think. An Product would have a easy to follow reference to the Image entinity and its properties.
Upvotes: 0