Fix named linking object queries across classes (#1734)
* Fix named linking object queries across classes * Add change log entry, remove debug code
This commit is contained in:
parent
6b3b34ae54
commit
497de5f3ea
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,3 +1,17 @@
|
|||
X.Y.Z Release notes
|
||||
=============================================================
|
||||
### Breaking changes
|
||||
* None.
|
||||
|
||||
### Enhancements
|
||||
* None.
|
||||
|
||||
### Bug fixes
|
||||
* Fix named LinkingObject queries across different classes (#1734).
|
||||
|
||||
### Internal
|
||||
* None.
|
||||
|
||||
2.3.3 Release notes (2018-3-23)
|
||||
=============================================================
|
||||
### Compatibility
|
||||
|
|
|
@ -159,8 +159,9 @@ inline void alias_backlinks(parser::KeyPathMapping &mapping, const realm::Shared
|
|||
for (const Property &property : it->computed_properties) {
|
||||
if (property.type == realm::PropertyType::LinkingObjects) {
|
||||
auto target_object_schema = schema.find(property.object_type);
|
||||
const TableRef table = ObjectStore::table_for_object_type(realm->read_group(), target_object_schema->name);
|
||||
std::string native_name = "@links." + std::string(table->get_name()) + "." + property.link_origin_property_name;
|
||||
const TableRef table = ObjectStore::table_for_object_type(realm->read_group(), it->name);
|
||||
const TableRef target_table = ObjectStore::table_for_object_type(realm->read_group(), target_object_schema->name);
|
||||
std::string native_name = "@links." + std::string(target_table->get_name()) + "." + property.link_origin_property_name;
|
||||
mapping.add_mapping(table, property.name, native_name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,32 @@ module.exports = {
|
|||
TestCase.assertEqual(people.filtered('25 IN parents.age').length, 1);
|
||||
},
|
||||
|
||||
testNamedLinkingObjectsAcrossClasses: function() {
|
||||
let realm = new Realm({schema: [schemas.Language, schemas.Country]});
|
||||
realm.write(() => {
|
||||
let english = realm.create('Language', {name: 'English'});
|
||||
let french = realm.create('Language', {name: 'French'});
|
||||
let danish = realm.create('Language', {name: 'Danish'});
|
||||
let canada = realm.create('Country', {name: 'Canada', languages: [english, french]});
|
||||
let denmark = realm.create('Country', {name: 'Denmark', languages: [danish, english]});
|
||||
let france = realm.create('Country', {name: 'France', languages: [french, english]});
|
||||
});
|
||||
let languages = realm.objects('Language');
|
||||
let spokenInThreeCountries = languages.filtered('spokenIn.@count == 3');
|
||||
TestCase.assertEqual(spokenInThreeCountries.length, 1);
|
||||
TestCase.assertEqual(spokenInThreeCountries[0].name, 'English');
|
||||
let spokenInTwoCountries = languages.filtered('spokenIn.@count == 2');
|
||||
TestCase.assertEqual(spokenInTwoCountries.length, 1);
|
||||
TestCase.assertEqual(spokenInTwoCountries[0].name, 'French')
|
||||
let spokenInOneCountry = languages.filtered('spokenIn.@count == 1');
|
||||
TestCase.assertEqual(spokenInOneCountry.length, 1);
|
||||
TestCase.assertEqual(spokenInOneCountry[0].name, 'Danish')
|
||||
let languagesSpokenInCanada = languages.filtered('spokenIn.name ==[c] "canada"');
|
||||
TestCase.assertEqual(languagesSpokenInCanada.length, 2);
|
||||
TestCase.assertEqual(languagesSpokenInCanada[0].name, 'English');
|
||||
TestCase.assertEqual(languagesSpokenInCanada[1].name, 'French');
|
||||
},
|
||||
|
||||
testMethod: function() {
|
||||
var realm = new Realm({schema: [schemas.PersonObject]});
|
||||
|
||||
|
|
|
@ -307,3 +307,20 @@ exports.MultiListObject = {
|
|||
'list2': 'string[]'
|
||||
}
|
||||
};
|
||||
|
||||
exports.Language = {
|
||||
name: 'Language',
|
||||
properties: {
|
||||
name: 'string',
|
||||
spokenIn: {type: 'linkingObjects', objectType: 'Country', property: 'languages'}
|
||||
}
|
||||
};
|
||||
|
||||
exports.Country = {
|
||||
name: 'Country',
|
||||
properties: {
|
||||
name: 'string',
|
||||
languages: 'Language[]',
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue