Skip to content

Commit 42e7dc2

Browse files
committed
Add test inspired by #1475
1 parent 10019fc commit 42e7dc2

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

Diff for: CHANGELOG.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
2.27.0 Release notes (2019-5-10)
1+
x.x.x Release notes (yyyy-MM-dd)
2+
=============================================================
3+
### Enhancements
4+
* None.
5+
6+
### Fixed
7+
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
8+
* None.
9+
10+
### Compatibility
11+
* Realm Object Server: 3.11.0 or later.
12+
* APIs are backwards compatible with all previous release of realm in the 2.x.y series.
13+
* File format: Generates Realms with format v9 (Reads and upgrades all previous formats)
14+
15+
### Internal
16+
* None.
17+
18+
2.27.0-rc.3 Release notes (2019-5-10)
219
=============================================================
320
NOTE: This release is only compatible with Realm Object Server 3.21.0 or later.
421

Diff for: tests/js/linkingobjects-tests.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,42 @@ module.exports = {
205205
});
206206

207207
TestCase.assertEqual(john.linkingObjectsCount(), 0);
208-
208+
209209
var olivier;
210210
realm.write(function() {
211211
olivier = realm.create('PersonObject', {name: 'Olivier', age: 0});
212212
realm.create('PersonObject', {name: 'Christine', age: 25, children: [olivier]});
213213
});
214-
214+
215215
TestCase.assertEqual(olivier.linkingObjectsCount(), 1);
216-
216+
217217
realm.write(function() {
218218
john.children.push(olivier);
219219
});
220220

221221
TestCase.assertEqual(olivier.linkingObjectsCount(), 2);
222+
},
223+
224+
testLinking: function () {
225+
var realm = new Realm({schema: [schemas.Activity, schemas.Log]});
226+
227+
realm.write(function () {
228+
realm.create('Activity', { id: 1, label: 'green', logs: [] });
229+
});
230+
231+
realm.write(function () {
232+
var newLog = realm.create('Log', { date: new Date() });
233+
var activity = realm.objectForPrimaryKey('Activity', 1);
234+
activity.logs.push(newLog);
235+
});
236+
237+
var activities = realm.objects('Activity');
238+
TestCase.assertEqual(activities.length, 1);
239+
var logs = realm.objects('Log');
240+
TestCase.assertEqual(logs.length, 1);
241+
TestCase.assertEqual(logs[0]['belongsTo'].length, 1);
242+
TestCase.assertEqual(logs[0]['belongsTo'][0]['id'], 1);
243+
244+
realm.close();
222245
}
223246
};

Diff for: tests/js/schemas.js

+17
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,20 @@ exports.Country = {
324324
}
325325
};
326326

327+
exports.Log = {
328+
name: 'Log',
329+
properties: {
330+
date: 'date',
331+
belongsTo: {type: 'linkingObjects', objectType: 'Activity', property: 'logs'}
332+
}
333+
};
334+
335+
exports.Activity = {
336+
name: 'Activity',
337+
primaryKey: 'id',
338+
properties: {
339+
id: {type: 'int', indexed: true},
340+
label: 'string',
341+
logs: 'Log[]',
342+
}
343+
};

0 commit comments

Comments
 (0)