ranked-model
ranked-model copied to clipboard
update 'with_same' if attribute nil
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
Rails 5.2.2.1 ruby 2.5.3p105
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?
No failing test or communication was received, so closing.