Skip to content

Bug: counter_cache update twice #13304

@ghost

Description

Example

# topic model
  belongs_to :node,       counter_cache: true
topic = Topic.find(1)  # node_id = 2
node = Node.find(1)

topic.node = node
topic.save

when you do that, active record update both node(id = 2) and node(id=1) topics_count twice. which make one add 2 and another minus 2

but if you do:

topic.node_id = node.id
topic.save
#or
topic.update_attributes(node_id: node.id)

you will be fine

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions