2

I try to extract some extra information if my query returns a result.

For example in this query, notable_for returns as "/music/musical_group" and I want to merge another query to extract some information about "/music/musical_group" like its "name"

[{
 "id": "/en/pearl_jam",
"mid":None,
"/common/topic/notable_for": [],
"name":[]   
}]

But if it does not return anything I dont want my query fails. For example, for the query below it returns a null list for the field "notable_for"

[{
"id": "/music/musical_group",
"mid":None,
"/common/topic/notable_for": [],
"name":[]
}]

How should I envelope my queries for such purpose?

cirik
  • 179
  • 1
  • 10

2 Answers2

2

You chose a pseudoproperty (*/common/topic/notable_for*) rather than a real property as your example and it behaves a little bit differently. For a real property, you can use @masouras's shorthand notation ([{}]) if you want to get all subproperties, but if you wanted to pick, say, one or two, the trick is to use the "optional" keyword.

For example, this query:

[{
  "id":  "/m/01mntvx",
  "type":"/music/musical_group",
  "/music/musical_group/member": [{
    "member": {
      "name": null
    },
    "optional": true
  }],
  "name":null
}]

will work even if a the band had no members listed.

Tom Morris
  • 10,490
  • 32
  • 53
  • thanks Tom! For anyone wondering, this does what I exactly want: [{ "id": "/en/pearl_jam", "mid": null, "/common/topic/notable_for": [{"optional": true}] }]​ – cirik Jan 09 '12 at 14:00
0

Is this what you are asking:

[{ "id": "/en/pearl_jam", "mid": null, "/common/topic/notable_for": [{}], }]​

http://tinyurl.com/7tchree

  • if we give id as "/music/musical_group" it fails. I want a query that does not fail for both. – cirik Jan 09 '12 at 13:57