ranked-model icon indicating copy to clipboard operation
ranked-model copied to clipboard

update 'with_same' if attribute nil

Open ilyario opened this issue 6 years ago • 2 comments

class Task < ApplicationRecord
  include RankedModel
  ranks :row_order, with_same: :parent_id
end

I'm use with_same and my model has parent_id equal to nil. And I have problem use '@task.update_attribute :row_order_position, new_position' if parent_id

@task.row_order 
=> -8379763 

project.tasks.where(parent_id: nil).rank(:row_order).pluck(:id, :row_order)
=>  [[43988, -8379763], [38997, -8378203], [39019, -8314748]]

@task.update_attribute :row_order_position, 1
=> UPDATE "tasks" SET "updated_at" = $1, "row_order" = $2 WHERE "tasks"."id" = $3  [["updated_at", "2019-03-21 11:27:17.220547"], ["row_order", -8382364], ["id", 43988]]

project.tasks.where(parent_id: nil).rank(:row_order).pluck(:id, :row_order)
=> [[43988, -8382364], [38997, -8378203], [39019, -8314748]]

but

If use alias :last it's works

ilyario avatar Mar 21 '19 11:03 ilyario

Rails 5.2.2.1 ruby 2.5.3p105

ilyario avatar Mar 21 '19 11:03 ilyario

Hi @ilyario, thanks for getting in touch with this issue. Do you think you'd be able to create a PR with a failing test case for this one?

brendon avatar Mar 21 '19 19:03 brendon

No failing test or communication was received, so closing.

brendon avatar Jun 04 '24 08:06 brendon