查询在强循环中基于一个表从另一个表中提取信息
Query for extracting info from one table based on other in strongloop
我有两个表帖子和分享,帖子有很多分享。 我想使用 userId(由所有者用户发布)获取帖子表中的所有数据,并使用相同的用户 ID 检查共享表,即如果某个人将帖子共享给其他用户,如果任何条件为真,我需要获取数据。
如果由所有者发布或由共享表中的其他用户共享,我想在帖子表中获取数据。
例:
表名称:帖子
id(pk) postname userid
1 abc 10
2 xxx 10
3 yyy 11
4 zzz 12
5 bbb 13
表名称:共享
id postid(fk) userid
1 3 10
2 4 10
3 3 11
4 1 12
预期输出:按用户 ID 10 查找的示例
id postname userid
1 abc 10 // this record created by user 10 (owner)
2 xxx 10 // this record created by user 10 (owner)
3 yyy 11 // this record shared by other user to user 10.
4 zzz 12 // this record shared by other user to user 10.
模型关系:后.json
"relations": {
"shares": {
"type": "hasMany",
"model": "share",
"foreignKey": "postid"
}
}
我尝试以下查询,但出现错误
{
"where": {
"or": [
{
"userid": 10
},
{
"include": {
"relation": "shares",
"scope": {
"where": {
"userid": 10
}
}
}
}
]
}
}
和//在这里我也只是检查帖子名称,但不需要这个问题。
{
"where": {
"or": [
{
"userid": 10
},
{
"postname": "xxx"
}
],
"include": {
"relation": "shares",
"scope": {
"where": {
"userid": 10
}
}
}
}
}
跳过"正式"关系,只使用操作钩子(https://docs.strongloop.com/display/public/LB/Operation+hooks),以便在执行查找时可以操作结果怎么样?
相关文章:
- 如何从..中提取信息..我称之为数组
- 从外部页面提取信息
- 查询在强循环中基于一个表从另一个表中提取信息
- 从 API 中提取信息并将其添加到数据库(平均堆栈)
- 从字符串中提取信息并将其保存到数据库
- 如何使用 JavaScript 从 HTML 中提取信息
- 正在从字符串中提取信息
- 从api中提取信息
- 如何从多行字符串中提取信息
- 我如何使用javascript从同一工作表上的2个不同的excel单元格中提取信息?我
- 从远程mongoDB提取信息
- 使用DOM从XML中提取信息
- 从数组中提取信息
- 如何查找以字符串"word"并从带有char #的字符串中提取信息
- 从生成的网站中提取信息
- 从javascript文件中提取信息到远程站点
- 使用jQuery从表和包中提取信息到JSON对象
- 从html防油精中提取信息
- WebApi从网站中提取信息
- JavaScript:从PHP脚本中提取信息