【发布时间】:2022-01-21 04:37:25
【问题描述】:
场景:
引用表:
first_name, email, estimate, etc.
quote_notes:
id, note, quote_id
所以,引号有_many_quote_notes。在我的报价模型中进行查询时,我正在尝试加入它。
function getAllNotes() {
return db('quote_notes')
.select('quote_notes.id', 'note', 'quote_notes.created_at', 'quote_id')
.join('quotes', 'quote_notes.quote_id', 'quotes.id')
.orderBy('id')
}
每当我对路径执行 get 请求时,它都会返回我查看的任何报价的所有 quote_notes。
router.get('/:id/notes', (req, res) => {
const {id} = req.params;
Quotes.getAllNotes(id).then((users) => {
res.status(200).json(users);
});
});
这是我的参考请求:
const getQuoteNotes = async () => {
let quoteNotes = await axiosWithAuth().get('/quotes/' + quoteId + '/notes');
setQuoteNotes(quoteNotes.data);
}
还有我的报价单:
table.bigInteger('quote_id')
.unsigned()
.index()
.references('id')
.inTable('quotes')
【问题讨论】:
标签: javascript postgresql express join knex.js