Skip to content

Bug in belongs_to when using counter_cache together with foreign_key #18988

@arnodirlam

Description

@arnodirlam

Hi,

when I use belongs_to with both counter_cache and foreign_key it doesn't update the counter cache correctly, since the update_counters method always operates on the table's primary key, instead of the foreign_key relevant in this case - as can be seen here.

I guess what could be done is to add a parameter holding the column that id references, which evaluates to the table's primary_key by default. This would have to be passed on by belongs_to when using increment_counter and decrement_counter here.

Should I try to make a pull request (would be my first to rails)? If yes, could someone please point me to file(s) appropriate fro the tests?

Cheers, Arno

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