Skip to content
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

Ignore @PersistedName when equal to field name #1240

Closed
lukaspieper opened this issue Jan 25, 2023 · 2 comments · Fixed by #1246
Closed

Ignore @PersistedName when equal to field name #1240

lukaspieper opened this issue Jan 25, 2023 · 2 comments · Fixed by #1246
Assignees

Comments

@lukaspieper
Copy link

lukaspieper commented Jan 25, 2023

Hi there,

just got my hand on the new release 1.6.0 and noticed to get errors when the field name is equal to the string specified in the annotation @PersistedName.

- Property '<Class>.<field>' has an alias '<alias>' that conflicts with a property of the same name.

I think that wasn't the case on Realm-Java? I like to add this annotation to every field (and class once #1138 is done) to make sure not to break things during refactoring in future. Furthermore I declare constants that are used in the annotation and for queries to have a single point of truth (hardcoded strings) avoiding having magic strings all around the code base (Kotlin does not have a fancy nameof() like C# that would solve this issue).

Would be great if the annotation could just be ignored when the value equals the field name until the field name is changed for whatever reason in future.

Many thanks and keep up the great work!

@lukaspieper
Copy link
Author

Thank you for working on this so quickly.

However, I think this is not fixed yet. If you add a second property with same PersistentName and FieldName to your test you should run into the following error:

[Realm] Kotlin names and persisted names must be unique. '' has already been used for the field on line <line-nr of the first annotation with same names>.

For me it looks like an empty string is not valid (see NO_ALIAS) as it seems to be used as a key anyway.

@rorbech
Copy link
Contributor

rorbech commented Feb 3, 2023

Ahh, yeah. Didn't knew we had a check for overlapping values that also needed an update. It isn't kicking in in our test as there is only one field that gets cleared with the "" value.

@rorbech rorbech reopened this Feb 3, 2023
@sync-by-unito sync-by-unito bot closed this as completed Feb 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants