coreData insert to to many relationship

Eric Yu

I see following example of adding to-many relationship back to CoreData

where 'currentDog' have many 'walks'

walk.date = NSDate()
let walks = currentDog.walks!.mutableCopy() as! NSMutableOrderedSet
walks.addObject(walk)
currentDog.walks = walks.copy() as? NSOrderedSet

and this is the way they insert the new walk

I was wondering why is it done that way? when one can simply do

walk.date = NSData()
walk.dog = currentDog

A more general question. Why would there be a need to insert an object to a Set before saving? When you can simply set the relationship of an object to it's related object or parent.

Wain

If the relationship is ordered then you may want to insert into the set. If not, and assuming your relationship is bi-directional as all should be, then your second example of setting the to-one end of the relationship is preferred because it's less code and therefore easier to maintain and read.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

coreData insert to to many relationship

From Dev

CoreData :NSFetchedResultsController one to many to many to many relationship

From Dev

coredata one to many relationship CoreDataGeneratedAccessors

From Dev

One to many relationship CoreData Swift

From Dev

One to many relationship CoreData Swift

From Dev

CoreData: Query to one-to-many-to-many relationship

From Dev

CoreData many to many relationship Best practices

From Dev

CoreData - many-to-many relationship with priorities

From Dev

CoreData: Fetch count of to-many relationship with NSDictionaryResultType

From Dev

CoreData fetch with NSSortDescriptor by count of to-many relationship

From Dev

INSERT statement for One to Many relationship

From Dev

Laravel insert in one to many relationship

From Dev

How to assign CoreData many-to-many relationship in Swift?

From Dev

Swift, CoreData and many-to-many-relationship: how to access order of subitems?

From Dev

Swift CoreData, saving data via a many to many relationship

From Dev

Bulk Insert Many-to-Many Relationship

From Dev

INSERT/DELETE examples in a many-to-many relationship

From Dev

How to insert data in many to many relationship

From Dev

PostgreSQL insert array many-to-many relationship

From Dev

EasyMapping do not map CoreData one to many relationship objects

From Dev

One to many CoreData relationship cannot be accessed when the object is fetched

From Dev

CoreData Predicate That Compares Two Properties in a Too-Many Relationship

From Dev

CoreData breaks To-Many relationship when entity assigned to multiple parents

From Dev

How to Insert, Update, Delete in a one to many relationship?

From Dev

it is possible to insert one to many relationship to database together?

From Dev

Laravel insert record with one to many relationship

From Dev

CoreData: Using NSPredicate to filter one to many to many relationship (error to-many key not allowed here)

From Dev

MySQL - How to insert into table that has many-to-many relationship

From Dev

Insert operation with many-to-many relationship using EF

Related Related

  1. 1

    coreData insert to to many relationship

  2. 2

    CoreData :NSFetchedResultsController one to many to many to many relationship

  3. 3

    coredata one to many relationship CoreDataGeneratedAccessors

  4. 4

    One to many relationship CoreData Swift

  5. 5

    One to many relationship CoreData Swift

  6. 6

    CoreData: Query to one-to-many-to-many relationship

  7. 7

    CoreData many to many relationship Best practices

  8. 8

    CoreData - many-to-many relationship with priorities

  9. 9

    CoreData: Fetch count of to-many relationship with NSDictionaryResultType

  10. 10

    CoreData fetch with NSSortDescriptor by count of to-many relationship

  11. 11

    INSERT statement for One to Many relationship

  12. 12

    Laravel insert in one to many relationship

  13. 13

    How to assign CoreData many-to-many relationship in Swift?

  14. 14

    Swift, CoreData and many-to-many-relationship: how to access order of subitems?

  15. 15

    Swift CoreData, saving data via a many to many relationship

  16. 16

    Bulk Insert Many-to-Many Relationship

  17. 17

    INSERT/DELETE examples in a many-to-many relationship

  18. 18

    How to insert data in many to many relationship

  19. 19

    PostgreSQL insert array many-to-many relationship

  20. 20

    EasyMapping do not map CoreData one to many relationship objects

  21. 21

    One to many CoreData relationship cannot be accessed when the object is fetched

  22. 22

    CoreData Predicate That Compares Two Properties in a Too-Many Relationship

  23. 23

    CoreData breaks To-Many relationship when entity assigned to multiple parents

  24. 24

    How to Insert, Update, Delete in a one to many relationship?

  25. 25

    it is possible to insert one to many relationship to database together?

  26. 26

    Laravel insert record with one to many relationship

  27. 27

    CoreData: Using NSPredicate to filter one to many to many relationship (error to-many key not allowed here)

  28. 28

    MySQL - How to insert into table that has many-to-many relationship

  29. 29

    Insert operation with many-to-many relationship using EF

HotTag

Archive