Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Maintaining an order with associations

$
0
0

@andywww wrote:

Hiya,

I’ve got a route planner app where a Ride hasMany Waypoints. I’m talking to a rails back end with JSONAPI. I want to offer the ability to insert a new waypoint between existing ones and also to remove waypoints and have the surrounding two re-order appropriately. I was thinking of either:

  1. Having some sort of re-ordering callback on the rails model that, when a new Waypoint record is persisted with a specified position attribute, it forces a recalculation of the position attribute for all subsequent Waypoints already part of the Ride.

  2. Manage this as part of the model creation function on Ember and update multiple local models, causing N subsequent update requests where N=number of waypoints after the newly inserted. Same for deletions.

This is purely subjective but the first option feels like the right thing to do because it feels more robust but it introduces the problem of having to get the changes back reflected in the Ember store. The latter feels bit fragile and potentially heavy on server traffic given how JSONAPI triggers one query per model updated.

I also don’t really know how well ember-data manages what would need to be websocket/push requests.

I’d be interested to hear if anyone has an opinion on the above and if there is a better way I may not have considered?

Thanks, Andy.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles