[Developers] querying a property in reverse
Augusto Callejas
acallejas at appliedminds.com
Sat Sep 1 18:41:46 UTC 2007
hi-
some properties do not have an inverse, like "Country of origin" for the
type "/film/film":
http://mjtemplate.org/examples/schemas/type.html?id=/film/film
so its easy to query the country for a given film in one direction:
{
"query":[{
"country":{
"name":null,
"type":"/location/country"
},
"name":"The Matrix",
"type":"/film/film"
}]
}
but not in the other direction:
{
"query":[{
"/type/reflect/any_reverse":[{
"link":{
"master_property":"/film/film/country"
},
"name":"The Matrix",
"type":"/film/film"
}],
"name":null,
"type":"/location/country"
}]
}
this problem arises when you have a general tree as a query and you need to
traverse in a certain direction. the simplest example is a query of the
form:
TypeA-->TypeB<--TypeC
where the directed arrow is a master property but does not have a reverse
property. any choice of the start of the query results in having to specify
the reverse property of a master property that doesn't have one.
augusto.
On 8/28/07 9:22 PM, "John Giannandrea" <jg at metaweb.com> wrote:
>
> Augusto Callejas wrote:
>> however, say i want to always want to start from the performance,
>> but i don't know the relationship from performance to film is
>> "film" but i
>> know the relationship from film to performance is "starring". how
>> can i
>> query on the "starring" property but in reverse without having to
>> perform a
>> separate query for the reverse property?
>
> You can do this in a roundabout way, with something like this:
>
> {
> "query":[{
> "/type/reflect/any_master":[{
> "link":{
> "master_property":{
> "reverse_property":"/film/film/starring"
> }
> },
> "name":"The Star Wars Holiday Special",
> "type":"/film/film"
> }],
> "character":"Han Solo",
> "type":"/film/performance"
> }]
> }
>
> However this requires that you know which property is the master and
> reverse
> otherwise you would need two clauses mirroring each other.
>
> Im curious about your use case that would know one property id but
> not be able to find the inverse from the schema. Can you say a
> little more
> about how this situation would arise in your app?
>
> -jg
>
More information about the Developers
mailing list