I'm using Backbone.Relational with Backbone.Marionette and Backbone.ioSync to sync over socket.io.
More specifically, I have a model
hasMany instances of mode
B through relation
bees. On load, all is well: data initialized and rendered appropriately. Then, another client adds another instance of
A.bees. The server sends a ping to the first client, which causes it to call
A.fetch(). In the success method of the fetch, I call
A.fetchRelated('bees'). The fetch method returns only a list of IDs for the
bees relation, triggering a
A, causing Backbone.Marionatte's collection view to create a new instance of the item view to display the new
B, which breaks the site since the new
B hasn't been fetched yet.
Trying to force the rendering of B's view to sync on a deferred object defined in A sounds like a complex hack with likely many edge cases to handle.
One idea is to allow
fetch to accept the
silent option. But it's probably tricky to trigger the
add events in the
success function of
Another idea is to make the serialization code on the server context aware and send the entire object, not just the IDs, when a new item is added. This is also sub optimal as it may cause unnecessary transfer of entire identical B's when they're added to different A's. It also adds a lot of complexity to the server code as the context would need to propagate throughout the serialization process.
Any thoughts or suggestions of how to approach this? I am open to solutions that may require changes to Backbone.Marionette or Backbone.Relational as long as it works.