Reputation: 6508
I have table users like
[
{
"id": "1" ,
"name": "John",
"groups": ["1", "2"]
}
{
"id": "2" ,
"name": "Jack",
"groups": ["1"]
}
]
And table groups like
[
{
"id": "1" ,
"name": "Admin",
"description": "Administrator"
},
{
"id": "2" ,
"name": "Guest",
"description": "Dear guest"
}
]
How can I make ReQL selection query with results like
[
{
"id": "1" ,
"name": "John",
"groups": ["Administrator", "Guest"]
},
{
"id": "2" ,
"name": "Jack",
"groups": ["Administrator"]
}
]
?
and
[
{
"id": "1" ,
"name": "John",
"groups": [
{
"id": "1" ,
"name": "Admin",
"description": "Administrator"
},
{
"id": "2" ,
"name": "Guest",
"description": "Dear guest"
}
]
},
{
"id": "2" ,
"name": "Jack",
"groups": [
{
"id": "2" ,
"name": "Guest",
"description": "Dear guest"
}
]
}
]
Upvotes: 0
Views: 41
Reputation: 642
Assuming Javascript API and by using .merge()
command:
r.table("users").merge(function(user) {
return {
groups: r.table("groups")
.getAll(r.args(user("groups")))
.getField("name")
.coerceTo("array")
};
})
and
r.table("users").merge(function(user) {
return {
groups: r.table("groups")
.getAll(r.args(user("groups")))
.coerceTo("array")
};
})
Upvotes: 0