getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Query removing other models in session. #123

Closed jimsynz closed 5 years ago

jimsynz commented 10 years ago

Hey there. I'm working on a completion system, using query to find the records we need.

In this case, we're searching by the number property of App.Part using @session.query('part', number: @get('partNumber') which works fine. Then I can add the order line to the order and it looks thus:

was_there

Then, as soon as I do the search a second time, all the parts appear to disappear from the collection:

now_its_gone

In summary

App.Part = Ep.Model.extend
  number: Ep.attr('string')
  orderedParts: Ep.hasMany('orderedPart')

App.OrderedPart = Ep.Model.extend
  part: Ep.belongTo('part')

All behaves as expected if I do the following:

part = @session.find('part', 2)
part.getProperties('id', 'name')
# => Object {id: "2", name: "Exclamation Lamp Sides"}
@session.query('part', number: 234)
# wait
part.getProperties('id', 'name')
# => Object {id: "2", name: "Exclamation Lamp Sides"}

It raises an exception if I try and associate it.

orderedPart = @session.create('orderedPart')
orderedPart.set('part', @session.find('part', 2))
orderedPart.get('part').getProperties('id', 'name')
# => Object {id: "2", name: "Exclamation Lamp Sides"}
@session.query('part', number: 234)
# wait
orderedPart.get('part').getProperties('id', 'name')
# TypeError: Cannot read property 'getProperties' of null

Is this expected behaviour? It certainly surprised me.

Thanks! :heart: your work.

jimsynz commented 10 years ago

(ping @ghempton)

ghempton commented 10 years ago

Sorry for the delay.

Hmmm.... this is certainly strange. Seems like it is removing the inverse for some reason. Can you post the json that is being returned?

jimsynz commented 10 years ago

Hey @ghempton.

So, here's the JSON for /api/v1/parts?number=234, I presume that's what you're interested in?

{
   "parts":[
      {
         "id":1,
         "number":"1234",
         "name":"Exclamation Lamp",
         "description":null,
         "price":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "cost":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "work_centre_id":1,
         "factory_id":1,
         "bill_of_materials_entry_ids":[
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13
         ]
      },
      {
         "id":2,
         "number":"2345",
         "name":"Exclamation Lamp Sides",
         "description":null,
         "price":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "cost":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "work_centre_id":4,
         "factory_id":1,
         "bill_of_materials_entry_ids":[
            14
         ]
      },
      {
         "id":3,
         "number":"2346",
         "name":"Exclamation Lamp Front",
         "description":null,
         "price":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "cost":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "work_centre_id":4,
         "factory_id":1,
         "bill_of_materials_entry_ids":[
            15
         ]
      },
      {
         "id":4,
         "number":"2347",
         "name":"Exclamation Lamp Back",
         "description":null,
         "price":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "cost":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "work_centre_id":4,
         "factory_id":1,
         "bill_of_materials_entry_ids":[
            16
         ]
      },
      {
         "id":5,
         "number":"2348",
         "name":"Exclamation Lamp Diffuser",
         "description":null,
         "price":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "cost":{
            "money":{
               "currency":"USD",
               "fractional":0
            }
         },
         "work_centre_id":4,
         "factory_id":1,
         "bill_of_materials_entry_ids":[
            17
         ]
      }
   ]
}
ghempton commented 10 years ago

I'm kind of stumped on this one. We do what is ostensibly the same thing in many places in our app....

Seems like there is a merging issue here. New data is coming back for the already associated part and it is overwriting the existing data (and more).

I think the only way for me to tackle this one is to try and get a test case to repro it and come up with a fix.

jimsynz commented 10 years ago

Happy to show you the code via Screenhero. Otherwise I'll try and build a repro for you.

ghempton commented 10 years ago

I'm in the middle of a big crunch right now so I don't have a ton of free time. Normally I'd totally be down for a screenhero session, but for the short term a repro would be great. Cheers.

jimsynz commented 10 years ago

No problem. I'll see what I can come up with.

ghempton commented 10 years ago

Also, I would try using master if you aren't already.