entangled icon indicating copy to clipboard operation
entangled copied to clipboard

ordering items

Open tommiller1 opened this issue 9 years ago • 5 comments

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.

tommiller1 avatar Jun 07 '15 17:06 tommiller1

Nvm issue lies with the angular plugin.

tommiller1 avatar Jun 13 '15 18:06 tommiller1

@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.

dchacke avatar Jun 13 '15 19:06 dchacke

@tommiller1 Also, what NVM issue are you experiencing?

dchacke avatar Jun 13 '15 19:06 dchacke

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.

tommiller1 avatar Jun 13 '15 21:06 tommiller1

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.

dchacke avatar Jun 13 '15 21:06 dchacke