-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backlink support #996
Backlink support #996
Conversation
8483279
to
46bca46
Compare
Pull Request Test Coverage Report for Build 3346094796
💛 - Coveralls |
dde705d
to
d795e54
Compare
@@ -161,6 +161,9 @@ extension ClassElementEx on ClassElement { | |||
todo: 'Remove the @PrimaryKey annotation from the field or set the model type to a value different from ObjectType.embeddedObject.'); | |||
} | |||
|
|||
// Computed fields go last. This is important for the schema generation. | |||
mappedFields.sort((a, b) => a.isComputed ^ b.isComputed ? (a.isComputed ? 1 : -1) : -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bit too much math. Isn't easier to use sortedby
? Like, on line 152, we could do something like:
final mappedFields = fields.realmInfo.sortedBy<num>((f) => f.isComputed ? 0 : 1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to pull in import 'package:collection/collection.dart
and I dislike the need to add <num>
bit to sortedBy
(<int>
won't do).
Also List.sort
is in-place, but apparently not stable 🤔 ... nor is sortedBy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me think a bit about this. I would like a stable sort, so that we only do the minimal needed changes to the ordering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its good. I have small suggestions.
80e108b
to
63c2b68
Compare
63c2b68
to
ceb9905
Compare
ceb9905
to
21d298c
Compare
b04f002
to
3352c30
Compare
@@ -149,7 +152,8 @@ extension ClassElementEx on ClassElement { | |||
|
|||
final objectType = ObjectType.values[modelInfo.value.getField('type')!.getField('index')!.toIntValue()!]; | |||
|
|||
final mappedFields = fields.realmInfo.toList(); | |||
// Realm Core requires computed properties at the end so we sort them at generation time versus doing it at runtime every time. | |||
final mappedFields = fields.realmInfo.toList()..sort((a, b) => a.isComputed ^ b.isComputed ? (a.isComputed ? 1 : -1) : -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure this sorting is super readable. How about:
final mappedFields = fields.realmInfo.toList()..sort((a, b) => a.isComputed ^ b.isComputed ? (a.isComputed ? 1 : -1) : -1); | |
final mappedFields = fields.realmInfo.toList()..sort((a, b) => a.isComputed == b.isComputed ? 0 : (a.isComputed ? 1 : -1)); |
Or even simpler:
final mappedFields = fields.realmInfo.toList()..sort((a, b) => a.isComputed ^ b.isComputed ? (a.isComputed ? 1 : -1) : -1); | |
final mappedFields = fields.realmInfo.toList()..sort((a, b) => a.isComputed ? 1 : -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a dealbreaker though - it should still be correct, just feels a little complicated to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to read it like: If a
and b
are different wrt. computed
, then if a
is computed
, a
goes last, otherwise a
goes first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter that they're different though? I think my last suggestion reads like: "if a
is computed, it goes last", which would be equivalent to "sort this array of bools in ascending order".
Co-authored-by: blagoev <lubo@blagoev.com>
3352c30
to
7bdd8ec
Compare
After trying this new feature I get the following error after running the generator:
I get the same error for Many-to-one and many-to-many relationships. Still anything wrong? |
@nielsenko Thanks for the quick answer. I will check it out! |
We now support named back links
Resolves: #693