Accessing nested relations in Bookshelf.js

 ̄綄美尐妖づ 提交于 2019-12-05 19:56:09

So the solution was to drop back to knex, grab all my comments for that topic with all related data, then build a tree. Here's the query I wound up using. Big thanks to rhys-vdw in the #bookshelf channel on irc.

                knex('comments').leftOuterJoin('votes', function() {
                    this.on('comments.id', 'votes.comment_id')
                        .andOn(knex.raw('votes.account_uuid = ?', req.user.uuid));
                })
                .leftOuterJoin('vote_count', function() {
                    this.on('comments.id', 'vote_count.comment_id');
                })
                .select('comments.*', 'votes.vote_type', 'vote_count.upvotes', 'vote_count.downvotes')
                .where('comments.topic_id', '=', topic_id)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!