entangled
entangled copied to clipboard
ordering items
Hey,
First of all great work on this gem!
I seem to have run into an issue though, my model returns objects in desc order with this: default_scope -> { order(created_at: :desc) }
The objects returned by entangle in the index method only take this into account on the first fetch. Subsequent fetches append the new objects at the end, is there any way to prepend new objects to the list?
Regards.
Nvm issue lies with the angular plugin.
@tommiller1 Thanks for reporting this! I am aware of this bug. It's because Entangled currently doesn't support scopes. In the future, the following collections should work:
Model.where(foo: 'bar')
Model.order(created_at: :desc)
Model.first(20)
# etc
At the moment, Entangled only understands .all
and .find
.
@tommiller1 Also, what NVM issue are you experiencing?
Nvm = Nevermind
It seems to work like its supposed to, the first stream contains the models in whichever order I have chosen with default_scope, subsequent notifications are sent one at a time so no ordering needed there. My problem lied with the angular plugin, it was push'ing newly created models into the 'this.resources.all' array hence the ordering problem. I made some changes to it so I can handle the create/update/destroy actions myself instead of letting the plugin do it all.
Oh, got it. Yes, the scopes will also have to be understood in the front end instead of just adding to the collection. I'll leave this issue open to mark this todo as pending.