【发布时间】:2016-10-09 14:01:15
【问题描述】:
我注意到了这个问题 (Use React Native Realm to Query through multiple List Objects),但无法让我的查询与 @blackpla9ue 提供的答案一起使用。
我有以下架构/模型,我想查询哪里 ProductReview->productId 等于 123,而 Review->reviewText 包含“一个简单的字符串”。
此查询仅返回 productId 123 的所有评论。
let allReviews = realm.objects('ProductReview', 'productId = "123");
let reviews = allReviews.filtered('reviews.reviewText CONTAINS[c] "a simple string"');
我还尝试删除 'productId = "123"',这只会导致所有产品的所有产品评论都被退回。它似乎要么完全忽略了filtered,要么我错过了一些东西。
class ProductReview extends Realm.Object{}
ProductReview.schema = {
name: 'ProductReview',
primaryKey: 'productId',
properties: {
productId: 'string',
averageRating: 'float',
totalReviewCount: 'int',
reviews: {type: 'list', objectType: 'Review'},
}
}
class Review extends Realm.Object{}
Review.schema = {
name: 'Review',
properties: {
rating: 'float',
title: {type: 'string', optional: true},
reviewText: {type: 'string', optional: true},
userLocation: {type: 'string', optional: true},
userNickName: {type: 'string', optional: true},
tags: {type: 'list', objectType: 'StringList'}
}
}
想看看我在这里可能做错了什么。
谢谢!
【问题讨论】:
标签: database mobile react-native realm