Schema of Product has many details like: productName, manufactured date, manufacturer name, product type etc. But I need to support flexibility of having no defined schema for product details. To achieve this below is the Realm-JS schema.
import Realm from 'realm';
export default class ProductModel extends Realm.Object { }
ProductModel.schema = {
name: 'ProductModel',
properties: {
productAttributes: { type: 'list', objectType: 'ProductDetailsModel' },
ID: { type: 'string', optional: true },
}
};
import Realm from 'realm';
export default class ProductDetailsModel extends Realm.Object { }
ProductDetailsModel.schema = {
name: 'ProductDetailsModel',
properties: {
attributeName: { type: 'string', optional: true },
attributeValue: { type: 'string', optional: true },
}
};
This flexibility is yielding in complexity of writing filter query. I need to be able to filter based on particular Product attribute name and Product Attribute values.
let query = "productAttributes.attributeName = " + "\"" + "Manufacturer" + "\"" + " AND productAttributes.attributeValue = [c]" + "\"" + "Pepsico" + "\"";
var productList = this.realm.objects('ProductModel').filtered(query).snapshot();
Please help me to write query to filter the ProductModel from DB matching ProductDetailsModel both attributeName and attributeValue ?
Current query does not match single ProductDetailsModel where attributeName ="Manufacturer" AND attributeValue = "Pepsico"