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 63c2b68
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 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

0 comments on commit 63c2b68

Please sign in to comment.