vendredi 1 juillet 2016

Core Data many to many through table with custom fields

My object model has article and media where articles reference media in a many to many relationship. The media may have different ordering and need to store the order of that media relative to the article, i,e, not on the media itself.

Core Data internally generates a sqlite database with the through table as:

article_id, media_id

Core Data/MagicalRecord objects are article and media:

class Article: NSManagedObject {
  ...
  @NSManaged var media: NSSet
}

class Media: NSManagedObject {
  ...
}

Is there a means in Core Data to persist the order of media in a through table mechanism? Instead I seem to need to create a new media record with its own position each time that media is used by an article.

In Django and Rails I make use of a through table in my model to store a position/order integer that says this media for this article is in this order. The table would have these columns:

article_id, media_id, position

It seems a through table with custom fields is not possible in Core Data?

Aucun commentaire:

Enregistrer un commentaire