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

LinkingObjects returns empty #7940

Closed
duncangroenewald opened this issue Sep 2, 2022 · 2 comments
Closed

LinkingObjects returns empty #7940

duncangroenewald opened this issue Sep 2, 2022 · 2 comments

Comments

@duncangroenewald
Copy link

duncangroenewald commented Sep 2, 2022

How frequently does the bug occur?

All the time

Description

LinkingObjects appears to always return empty. Am I doing something wrong or are there some conditions for it to work.

The two model objects are shown below.

Note that the group.marks property returns a correct list of marks but the mark.groups property is always empty. Did I miss something

// Group marks and routes
class Group: Object {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var name: String = "New Group"
    @Persisted var comments: String = ""
    @Persisted var iconName: String = ""
    @Persisted var type: String = ""
    
    @Persisted var marks: List<Mark>
    
    @Persisted var routes: List<Route>
    
    convenience init(name: String, comments: String, iconName: String, type: String) {
        self.init()
        
        self.name = name
        self.comments = comments
        self.iconName = iconName
        self.type     = type
    }
    
}

class Mark: Object {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var name: String = "New Mark"
    @Persisted var latitude: Double = 34.0
    @Persisted var longitude: Double = 20.0
    @Persisted var comments: String = ""
    @Persisted var iconName: String = ""
    @Persisted var type: String = ""
    @Persisted var number: Int = 1
    
    let groups = LinkingObjects(fromType: Group.self, property: "marks")
    
    convenience init(name: String, startLocation: CLLocationCoordinate2D, comments: String, iconName: String) {
        self.init()
        
        self.name = name
        self.latitude = startLocation.latitude
        self.longitude = startLocation.longitude
        self.comments = comments
        self.iconName = iconName
    }
    
}

Stacktrace & log output

N/A

Can you reproduce the bug?

Not yet

Reproduction Steps

N/A

Version

10.28.6

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

macOS 12.5.1

Build environment

Xcode version: 13.4.1
Dependency manager and version: SPM

@duncangroenewald
Copy link
Author

I was using the wrong property definitions

@persisted(originProperty: "marks") var groups: LinkingObjects
@persisted(originProperty: "marks") var routes: LinkingObjects

@Arshad-iOSDeveloper
Copy link

Can you paste the full code?

@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

No branches or pull requests

2 participants