Search code examples
node.jsmodelrelationshiploopbackjs

Post and Tags model relations


What's the relation for posts and tags?
I wonder if it's posts hasMany tags and tags hasMany posts,
or posts hasMany tags and tags hasAndBelongsToMany posts,
or posts embedsMany tags ??

I'm really confused, please help.. I'm developing a quiz app


Solution

  • Posts and Tags are many-to-many relationship. You can think of, a post can have several tags, and a tag can be used by several posts.

    You should express a hasAndBelongsToMany relation between Post and Tag models.

    See also: HasAndBelongsToMany relations