如何在bookshelf.js关系中使用2个不同的目标id?

时间:2017-08-31 07:55:06

标签: javascript node.js bookshelf.js

我有2个<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="kadd">A</div> <div class="kadd">B</div> <div class="kadd">C</div> <div class="kadd">D</div> <div class="kadd">E</div> <div class="kadd">F</div> <div class="kadd">G</div>tablesuser,其中包含以下数据:

friend

当我查询user id | name | gender ---------------------------- 1 | John | male 2 | Jessica | female 3 | Bryan | male 4 | Mark | male 5 | Jane | female friend id | user1 | user2 ------------------------- 1 | 1 | 3 2 | 1 | 4 3 | 2 | 1 4 | 2 | 4 5 | 2 | 5 6 | 5 | 1 7 | 4 | 2 时,如何使用Bookshelf.js关系获得以下结果:

user

请注意,好友列表是按字母顺序排列

我尝试了"data" : { "name": "John", "gender": "male", "friends" : [ { "id": 3, "name": "Bryan", "gender": "male" }, { "id": 5, "name": "Jane", "gender": "female" }, { "id": 2, "name": "Jessica", "gender": "female" }, { "id": 4, "name": "Mark", "gender": "male" } ] } 的{​​{1}}关系,但我只得到:

Model.belongsToMany

基本上,我想在我的查询中包含bookshelf.js的{​​{1}}和"data" : { "name": "John", "gender": "male", "friends" : [ { "id": 3, "name": "Bryan", "gender": "male" }, { "id": 4, "name": "Mark", "gender": "male" } ] } ,但我不知道该怎么做。如果可能的话,我想在朋友列表中加入Jessica和Jane。

这是我现有的代码:

user1

谢谢。

0 个答案:

没有答案