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

Accessing parent properties of CoreStoreObject entity is prohibited? #507

Open
vovsyannikov opened this issue Jun 26, 2024 · 0 comments
Open

Comments

@vovsyannikov
Copy link

I have a structure in may app where I have a parent object:

open class BaseContact: CoreStoreObject {
    @Field.Stored("externalId")
    open var externalId: Int?

    @Field.Stored("isUser")
    open var isUser: Bool = false    

    // Other props
}

A child and another entity:

final public class Contact: BaseContact {
    // Other props

    @Field.Relationship("userDL", inverse: \DBS.UserDL.$contact)
    public var userDL: DBS.UserDL?

    // Other props
}

final public class UserDL: CoreStoreObject {
    // Other props

    @Field.Relationship("contact")
    public var contact: DBS.Contact?

    // Other props
}

When trying to fetch Contact specifically by isUser property I get an error:

func contactIsUser() -> DBS.Contact? {
    try? fetchOne(where: \DBS.Contact.$isUser == true)
}

Binary operator '==' cannot be applied to operands of type 'KeyPath<DBS.Contact, FieldContainer<DBS.BaseContact>.Stored<Bool>>' and 'Bool'

Same thing with:

func currentUserDL(withContactID externalId: Int?) -> DBS.UserDL? {
    try? fetchOne(where: \.$contact ~ \.$externalId == externalId)
}

There's a different error but in the same vein:
Operator function '~' requires the types 'Optional<DBS.Contact>.DestinationObjectType' (aka 'DBS.Contact') and 'FieldContainer<DBS.BaseContact>.Stored<Int?>.ObjectType' (aka 'DBS.BaseContact') be equivalent

@vovsyannikov vovsyannikov changed the title Accessing parent properties of CoreStoreObject is prohibited? Accessing parent properties of CoreStoreObject entity is prohibited? Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant