core data - Non-optional to-many relationship allows nil or empty set -


i have sample data structure: table "groups" , table "items". groups can contains 0 or more items , item must linked minimum 1 or more groups:

groups   |--------- to-many, optional ---------->>|items ---------|<<------- to-many, non-optional! -------|-------- groupname|                                        |itemname items    |                                        |groups 

i create nsmanagedobject subclasses. both trivial here items:

class items:nsmanagedobject {     @nsmanaged var itemname:string     @nsmanaged var groups:set<groups> //attention: there no ! or ? } 

in code below expecting catch error:

var item = items() item.itemname = "aaaa" {     try items.moc.save() //moc - static field in items "linked" managedobjectcontext } catch {     print(error) } 

but there no errors! item saves coredata empty groups. can't figure out why? but if make items groups relation non-optional to-one (in class items groups field became @nsmanaged var group:groups) exception throws expected.

i know, can implement in items class function validategroups, can check if groups nil or empty, want know: there mistake cant find or core data bug (or feature)? more, implement storage logic database (in sql triggers, can't live without foreign keys, constraints etc).

so, please, me understand this. thanks!

problem solved, willeke! when set minimum count in item's entity relation properties problem disappeared.

enter image description here


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -