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

Inability to setParameter or ordered by Id field #51

Open
singlakarun opened this issue May 14, 2021 · 4 comments
Open

Inability to setParameter or ordered by Id field #51

singlakarun opened this issue May 14, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@singlakarun
Copy link

This is pretty coming scenario to execute queries on Id field

// objectbox: entity
class MyEntity {
    var id: Id = 0
//more fields
}

let box: Box<MyEntity> = ...
let query = box.query {
     MyEntity.id.isEquals(to: 0)
}.ordered(by: MyEntity.id) --> COMPILATION ERROR here
.build()

query.setParameter(MyEntity.id, 0) --> COMPILATION ERROR here
@singlakarun singlakarun added the bug Something isn't working label May 14, 2021
@greenrobot
Copy link
Member

Some people say IDs should not used in queries at all as they should not represent any application data. What's your use case?

@singlakarun
Copy link
Author

I am storing chat messages in a table and wanted to extract the last message inserted. Doing it via timestamp might be inaccurate as theoretically there could be multiple messages generated in a millisecond. Only way out is to use my own auto increment column which I want to avoid.
Also I wanted to sort the messages in the reverse insertion order.

@greenrobot
Copy link
Member

Yes, IDs "happen" to work for that local case. Technically, we don't give guarantees that this will stay like this forever, and, e.g. if you'd use Sync, it would break right away.

Other than that, we'll look into the compilation issue, of course. It will take some time though, as there are other things on our priority queue.

@greenrobot-team
Copy link
Member

we'll look into the compilation issue

This is because ordered(by) and setParameter() do not support Id properties (they are restricted to Property<ObjectBox.QueryBuilder<E>.EntityType, T, Void>, but for Id properties the last type parameter is not Void).

The methods would have to be changed to explicitly allow using Id properties. So changing this into an enhancement suggestion.

@greenrobot-team greenrobot-team added enhancement New feature or request and removed bug Something isn't working labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants