Reputation: 723
I have a "Note" entity for my application, where its attributes are "Title", "Body", and "Tags".
I'm having trouble with the "Tags" attribute; I want to be able to input multiple tags when creating the Note, and then the program will be able to give me other Notes that have the same tag (Exactly like how Stackoverflow uses tags for questions). I'm not quite sure what the relationship between the entities should be.
How should I approach this problem?
Upvotes: 4
Views: 130
Reputation: 40211
Tag
shouldn't be an attribute, but a many-to-many relationship. A Note
can have multiple Tags
(I assume) and a Tag
can be added to multiple different Notes
.
This way you'll be able to set up a fetch request to return all the Notes
that have a specific Tag
.
Upvotes: 2
Reputation: 4279
Create Tag entity and add to-many relationship from Note to Tag and also to-many relationship from Tag to Note (and set set them to be inverses of each other).
Upvotes: 2