Comment: Common API (api/databases/common.md)
Closed this issue · 1 comments
Comment/Problem
I'm trying to do something really simple based on sequelize models.
Lets say we have to models Posts and Tags.
Posts.belongsTo(Tags);
Tags.hasMany(Posts);
Perhaps it's documented on how to call Tags including Posts... but can't seem to find it ;)
Edit: found it in the FAQ https://docs.feathersjs.com/help/faq.html#how-do-i-do-associations
But how can we add a Post to one Tag ?
Perhaps this is so obvious to some that it didn't need to shown in documentation, but I'm newbee to feathersjs and still stuck on this after several days.
app.services.tags
.create({
title: 'myTag',
})
.then(myTag => {
// how can one o something like
// myTag.addPost({ title: 'myPost'}) ?
})
There is more documentation in https://github.com/feathersjs-ecosystem/feathers-sequelize#associations.
The simplest way to associate an existing model is by passing the id field that is being generated by Sequelize: `app.service('posts').create({ tagId: myTag.id })