Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: blagoev <lubo@blagoev.com>
  • Loading branch information
nielsenko and blagoev committed Oct 28, 2022
1 parent c2945f2 commit ceb9905
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Added `MutableSubscriptionSet.removeByType` for removing subscriptions by their realm object type. (Issue [#317](https://github.com/realm/realm-dart/issues/317))
* Support results of primitives, ie. `RealmResult<int>`. (Issue [#162](https://github.com/realm/realm-dart/issues/162))
* Support notifications on all managed realm lists, including list of primitives, ie. `RealmList<int>.changes` is supported. ([#893](https://github.com/realm/realm-dart/pull/893))
* Support named backlinks on realm models. You can now add and annotate a realm object iterator field with `@Backlink(#symbolName)`. ([#996](https://github.com/realm/realm-dart/pull/996))
* Support named backlinks on realm models. You can now add and annotate a realm object iterator field with `@Backlink(#fieldName)`. ([#996](https://github.com/realm/realm-dart/pull/996))

### Fixed
* Fixed a wrong mapping for `AuthProviderType` returned by `User.provider` for google, facebook and apple credentials.
Expand Down
7 changes: 4 additions & 3 deletions common/lib/src/realm_common_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ class Ignored {
const Ignored();
}

/// Indicates a backlink property.
/// Indicates that the field it decorates is the inverse end of a relationship.
/// {@category Annotations}
class Backlink {
final Symbol symbol;
const Backlink(this.symbol);
/// The name of the field in the other class that links to this class.
final Symbol fieldName;
const Backlink(this.fieldName);
}
2 changes: 1 addition & 1 deletion generator/lib/src/dart_type_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ extension DartTypeEx on DartType {

DartType get mappedType {
final self = this;
final provider = session.typeProvider;
if (isRealmCollection) {
if (self is ParameterizedType) {
final mapped = self.typeArguments.last.mappedType;
if (self != mapped) {
final provider = session.typeProvider;
if (self.isDartCoreList) {
final mappedList = provider.listType(mapped);
return PseudoType('Realm${mappedList.getDisplayString(withNullability: true)}', nullabilitySuffix: mappedList.nullabilitySuffix);
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/src/field_element_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ extension FieldElementEx on FieldElement {
);
}

final sourceFieldName = backlink.value.getField('symbol')?.toSymbolValue();
final sourceFieldName = backlink.value.getField('fieldName')?.toSymbolValue();
final sourceType = (type as ParameterizedType).typeArguments.first;
final sourceField = (sourceType.element2 as ClassElement?)?.fields.where((f) => f.name == sourceFieldName).singleOrNull;

Expand Down
2 changes: 1 addition & 1 deletion generator/test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LinesEqualsMatcher extends Matcher {
}
}

if (actualLines.length > expectedLines.length) {
if (actualLines.length != expectedLines.length) {
matchState["Error"] = "Different number of lines. \nExpected: ${expectedLines.length}\nActual: ${actualLines.length}";
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions test/backlinks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class _Source {
@RealmModel()
class _Target {
@Backlink(#oneTarget)
late Iterable<_Source> oneToMany; // computed property, so must go last in generated class!
late Iterable<_Source> oneToMany; // will be reordered by the generator to go after name

String name = 'target';

@Backlink(#manyTargets)
late Iterable<_Source> manyToMany; // computed property, so must go last in generated class!
late Iterable<_Source> manyToMany;
}

Future<void> main([List<String>? args]) async {
Expand Down

0 comments on commit ceb9905

Please sign in to comment.