derbyjs / racer

Realtime model synchronization engine for Node.js
1.19k stars 118 forks source link

[Bug] Subscribing multiple queries using array returns cross-results #33

Closed fjbsantiago closed 12 years ago

fjbsantiago commented 12 years ago

When subscribing mutliple queries, their results get crossed. Each scopedModel... returned in the Callback function carries the results of its query plus the results of the other queries.

Expected: Scoped model "seniors" should only have 1 ocurrency of each person over 50 years old.

Actual Result: In this case, scoped model "seniors" will contain people over 50, plus people over 50 that live in Lisbon, plus another copy of everyone that satisfies the first two queries.


    peopleOlderThan = model.query('people').olderThan(50)
    peopleFrom = model.query('people').from('Lisbon')
    people = model.query('people').everyone()
    queries = [
                peopleOlderThan
                peopleFrom
                people
            ]

    model.subscribe queries..., (err, seniors, residents, everyone) ->
                console.log seniors.get()

The same happens if the queries are performed independently.


model.subscribe peopleOlderThan, (err, seniors) -> console.log seniors.get()
model.subscribe peopleFrom, (err, residents) ->  console.log residents.get()
model.subscribe people, (err, everyone) ->  console.log everyone.get()

The first query will return correctly. The second one will have its own result plus the result from query one. The third one will return the results from all three queries.