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

Cannot define model consisting of only a LinkingObjects property #8414

Closed
lukaskollmer opened this issue Nov 5, 2023 · 2 comments · Fixed by #8484
Closed

Cannot define model consisting of only a LinkingObjects property #8414

lukaskollmer opened this issue Nov 5, 2023 · 2 comments · Fixed by #8484

Comments

@lukaskollmer
Copy link

lukaskollmer commented Nov 5, 2023

How frequently does the bug occur?

Always

Description

Consider the following model:

class Note: Object {
    @objc dynamic var user: User?
}
class User: Object {
    let notes = LinkingObjects(fromType: Note.self, property: #keyPath(Note.user))
}

Calling -[User init] fails with the following exception: "No properties are defined for 'User'. Did you remember to mark them with '@objc' in your model?".

This happens both when using the legacy @objc syntax, as well as with the new @Persisted property wrappers.

IMO this should work, since there is a property here (the LinkingObjects, which apparently gets ignored by the "are there properties" check?)

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

10.44.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

macOS 13.4.1 (22F82)

Build environment

Xcode version: 15.0.1
Dependency manager and version: SPM, shipped w/ Xcode

@Jaycyn
Copy link

Jaycyn commented Nov 5, 2023

Interesting and duplicated

class Note: Object {
    @Persisted var user: User?
}
class User: Object {
    @Persisted(originProperty: "user") var notes: LinkingObjects<Note>
}

I generally consider LinkingObjects as a 'computed property' that doesn't exist until called so it 'makes sense' why it's not seen as an actual property. However, it should still work without throwing an error.

@nirinchev
Copy link
Member

That is correct - linking objects properties are computed and as such not part of the schema. That being said, having objects with no schema is supported by Realm and only prevented by the Swift SDK. While it'd be trivial to remove the check, I'm thinking it was probably added as a safeguard since it may have been a common mistake not to annotate your properties correctly and wonder why the data is not being persisted. I'll talk to the team and see what the best course of action is here.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 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