ios - Handle many-to-many relations in CloudKit -
i'm trying create tagging system using cloudkit. have type called article , tag type called tag. each article can have multiple tags applied. want data normalied since same tags can appear on several articles , articles can have multiple tags, need many-to-many relation. in old school db-stuff require junction table.
how do in cloudkit?
in of apples documentation can find examples of one-to-many relations.
so have created junction-table type called articletag, consists og 2 ckreferences. 1 article reference , 1 tag reference.
this should work, best way query tags per article?
kind regards, esben
there isn't mechanism "join" queries in cloudkit traditional relational database, should able accomplish want using field type "reference list" on articles. let's assume following:
- your article record type has "tags" field of type reference list. can set in cloudkit dashboard.
- you have tag record type
- when tagging article, first lookup (and potentially create) tag record each tag, add ckreference article.tags list field using each of tag record ids.
you can lookup article's tags using ids in tags field, , can find articles tagged specific tag using tag record id , ckquery predicate uses contains operation check list membership.
Comments
Post a Comment