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

Make PropertyQuery consider the Query order #41

Open
adgvcxz opened this issue Aug 9, 2020 · 1 comment
Open

Make PropertyQuery consider the Query order #41

adgvcxz opened this issue Aug 9, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@adgvcxz
Copy link

adgvcxz commented Aug 9, 2020

Version : v1.3.1

Description:
When I use the PropertyQuery method to query, the sorting is incorrect

// objectbox: entity
final class Item {
    var id: Id = 0
    var data: Int64 = 0
    var created: Int64 = 0
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let store = try! createStore()
        let box: Box<Item> = store.box()
        putData(box: box)
        let build = try! box.query().ordered(by: Item.created).build()
        let values = try! build.property(Item.data).find()
        let times = try! build.property(Item.created).find()
        
        print(values)
        print(times)
        
    }
    
    private func putData(box: Box<Item>) {
        let value: [Int64] = [64087, 56654, 427, 95156, 75358]
        let times: [Int64] = [1596884723268, 1596884598790, 1596883589545, 1596880357258, 1596878457071]
        for i in 0..<value.count {
            let item = Item()
            item.created = times[i]
            item.data = value[i]
            try! box.put(item)
        }
    }
}

private func createStore() throws -> Store {
    let directory = try FileManager.default.url(
        for: .applicationSupportDirectory,
        in: .userDomainMask,
        appropriateFor: nil,
        create: true
    ).appendingPathComponent("Test")
    try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false, attributes: nil)
    return try Store(directoryPath: directory.path)
}

Output:

[64087, 56654, 427, 95156, 75358]

[1596884723268, 1596884598790, 1596883589545, 1596880357258, 1596878457071]
@greenrobot
Copy link
Member

This is a documented limitation:

Currently, property queries do not honor the ordered(by:,flags:) setting. If you need a fixed order for your proerty query results, you must sort them manually after retrieving them.

I'm changing this issue to a feature request.

@greenrobot greenrobot added the enhancement New feature or request label Aug 11, 2020
@greenrobot greenrobot changed the title PropertyQuery: The order of the results is incorrect Make PropertyQuery consider the Query order Aug 11, 2020
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

2 participants