I have the following structure in RethinkDB
{ "id": "1", "values": [{ "id": 1, "firstname": "foo" }] },
{ "id": "2", "values": [{ "id": 2, "firstname": "bar" }] }
How can I update each "values" array and add an additional property to it?
For instance I'd like to achieve
{ "id": "1", "values": [{ "id": 1, "firstname": "foo", "lastname": null }] },
{ "id": "2", "values": [{ "id": 2, "firstname": "bar", "lastname": null }] }
Something like:
r.table('test').get(id).update(function(row) {
return {values: row('values').map(function(val)
return val.merge({lastname: null});
});
})
Related
I have a json like this:
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "naist street",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]
}
And get a json path expression: $.phoneNumbers.*.type
How can I delete the keys by this expression in Go?
I'm accessing a single model and loading its relation using this code below,
return Application::select('id')->with([
'oneApplicant:id,user_id,first_name,last_name,email',
'oneApplicant.referrer:id,parent_id,first_name,last_name,email',
'oneApplicant.referrer.parent:id,first_name,last_name,email',
])->find($id);
and the response is this
{
"id": 200,
"oneApplicant": [
{
"id": 200,
"userId": 9,
"firstName": "Mac",
"lastName": "Lebsack",
"email": "edicki#example.net",
"referrer": {
"id": 9,
"parentId": 5,
"firstName": "Aurelia",
"lastName": "Boyle",
"email": "uhirthe#example.org",
"parent": {
"id": 5,
"firstName": "Dewitt",
"lastName": "Bednar",
"email": "tluettgen#example.net"
}
}
}
]
}
I wanted to convert the response to something like this (couldn't care less about the other attribute, all I need is first_name, last_name & email )
[
{
"id": 200,
"userId": 9,
"firstName": "Mac",
"lastName": "Lebsack",
"email": "edicki#example.net",
},
{
"id": 9,
"parentId": 5,
"firstName": "Aurelia",
"lastName": "Boyle",
"email": "uhirthe#example.org"
},
{
"id": 5,
"firstName": "Dewitt",
"lastName": "Bednar",
"email": "tluettgen#example.net"
}
]
I was testing with map and transform but it doesn't even work and as I understand with the error, my result is not a collection.
Can someone guide me on how to achieve this,
Thanks
This is extremely weird for me - my code is very basic:
<v-select
chips
multiple
:items="areas"
v-model="person.applicant.areas"
:label="trans('Areas of interest')"
item-text="name"
item-value="id"
></v-select>
The items when echoed right before that with {{areas}} returns as follows:
[
{ "interestsAreas": "TEst", "id": 0, "name": "TEst" },
{ "interestsAreas": "Test2", "id": 1, "name": "Test2" },
{ "interestsAreas": "Something", "id": 0, "name": "Something" },
{ "interestsAreas": "1", "id": 1, "name": "1" },
{ "interestsAreas": "2", "id": 2, "name": "2" },
{ "interestsAreas": "3", "id": 3, "name": "3" }
]
Yet, whatever I do the v-select drops "Something" and "1" out of the dropdown even if I rename them or whatever.
I can't catch the logic behind dropping some of them, is there any known bug or something that I am not doing right in the invocation?
I am guessing it has something to do with the item-value, as id needs to be unique
[
{ "interestsAreas": "TEst", "id": 0, "name": "TEst" },
{ "interestsAreas": "Test2", "id": 1, "name": "Test2" },
{ "interestsAreas": "Something", "id": 0, "name": "Something" },// the id value is already used so try changing it
{ "interestsAreas": "1", "id": 1, "name": "1" },//same for this one as well
{ "interestsAreas": "2", "id": 2, "name": "2" },
{ "interestsAreas": "3", "id": 3, "name": "3" }
]
This question already has answers here:
Ruby: Easiest Way to Filter Hash Keys?
(14 answers)
Closed 6 years ago.
I am a beginner with Ruby, and I have the following Json array:
"elements": [
{
"type": "Contact",
"id": "1",
"createdAt": "131231235",
"name": "test",
"updatedAt": "1456328049",
"accountName": "Mr Test",
"country": "China",
"firstName": "Test",
"lastName": "lastNameTest",
},
{
"type": "Contact",
"id": "2",
"createdAt": "156453447",
"name": "test2",
"updatedAt": "124464554",
"accountName": "Mr Test2",
"country": "Germany",
"firstName": "Test2",
"lastName": "lastNameTest2",
},...
]
I want to filter out only a few keys + values: for example I want to return only the id,name,accountName,firstname and lastname.
So the exspected output is the following:
"elements": [
{
"id": "1",
"name": "test",
"accountName": "Mr Test",
"firstName": "Test",
"lastName": "lastNameTest",
},
{
"id": "2",
"name": "test2",
"accountName": "Mr Test2",
"firstName": "Test2",
"lastName": "lastNameTest2",
},...
]
I tried the following: create a filter array which has the elements I want to return and then map over the items but then I get stuck..
filters = []
filters.push("accountName")
filters.push("lastName")
filters.push("firstName")
filters.push("Id")
output["elements"].each do |item|
result = []
item.map {|key,value|filters.include? key}
result.push(?)
Thank you for the help.
Check this out, you should be able to work out from this:
output = { "elements": [
{
"id": "1",
"name": "test",
"accountName": "Mr Test",
"firstName": "Test",
"lastName": "lastNameTest",
"somethoong": "sdsad"
},
{
"id": "2",
"name": "test2",
"accountName": "Mr Test2",
"firstName": "Test2",
"lastName": "lastNameTest2"
}
]}
attribs = %w(accountName lastName firstName id)
output[:elements].each do |item|
item.delete_if{|k,v| !attribs.include?(k.to_s)}
end
Here is a very simple line of code I am running:
return User::orderBy('first_name', 'asc')->get();
I expect to get the returned result in alphabetical order. Here is what I get:
{
"id": "1",
"first_name": "Kousha",
...
},
{
"id": "10",
"first_name": "Monica",
...
},
{
"id": "9",
"first_name": "Alex",
...
},
{
"id": "2",
"first_name": "Ali",
...
},
{
"id": "7",
"first_name": "Chris",
...
},
{
"id": "5",
"first_name": "Amin",
...
},
{
"id": "6",
"first_name": "Felix",
...
},
{
"id": "8",
"first_name": "Aleksi",
...
},
{
"id": "3",
"first_name": "Ryan",
...
},
{
"id": "4",
"first_name": "Paul",
...
}
If I try the order in descending order, I get another gibberish result. The only thing the order works for is the id. What am I missing here?