Create query across backlink just like you would do with regular links.
Successfully retrieve results.
Property 'onSale' is not a link in object of type 'Combination'
class Product {};
Product.schema = {
name: 'Product',
primaryKey:'productId',
properties: {
productId:'int',
product:'string'
combinations: {type: 'linkingObjects', objectType: 'Combination', property: 'products'}
}
};
class Combination {};
Combination.schema = {
name: 'Combination',
properties: {
onSale: {type: 'string'},
products: {type: 'list',objectType:'Product'},
}
};
and
let queryFilter = 'combinations.onSale = "yes" AND productId = 1';
let data = realm.objects('Product').filtered(queryFilter);
I have reproduced it in pure Javascript:
const Realm = require('realm')
const ProductSchema = {
name: 'Product',
primaryKey:'productId',
properties: {
productId:'int',
product:'string',
combinations: {type: 'linkingObjects', objectType: 'Combination', property: 'products'}
}
}
const CombinationSchema = {
name: 'Combination',
properties: {
onSale: {type: 'string'},
products: {type: 'list', objectType:'Product'}
}
}
Realm.open({
schema: [ProductSchema, CombinationSchema]
}).then(function (realm) {
let queryFilter1 = 'onSale = "yes" AND products.productId = 1'
let data1 = realm.objects('Combination').filtered(queryFilter1)
let queryFilter2 = 'combinations.onSale = "yes" AND productId = 1'
let data2 = realm.objects('Product').filtered(queryFilter2)
})
Closing as #1660 has been merged. It will be released soon.
Amazing work :smile:
All credit go to @ironage
Has this been released? I'm using 2.6.0 and still cannot get queries across backlinks to work. Two documentation sources claim that it is supported:
From https://realm.io/docs/javascript/latest#queries:
parents.age > 25 and parents.@count == 2.From: https://github.com/realm/realm-js/blob/master/docs/tutorials/query-language.md:
Other objects can link to an object and you can query on that releationship using the @links and @links.ClassName.PropertyName syntax. If the relationship of the LinkingObject is named, use the name in the query just like you would use any other property for readability. If the relationship is not named, you can use the @links.ClassName.PropertyName syntax where ClassName.PropertyName describes the forward relationship.
I cannot get either option to work.
@sellmeadog yes, I'd expect it to be working since 2.3.4. Are you able to share your query and the schemas of the linked classes if not your actual models, a minimal example that can reproduce the behaviour you see?
Most helpful comment
Closing as #1660 has been merged. It will be released soon.