magnusvk/counter_culture

STI and Polymorphic issue with fix counts method on self-referential models

Closed this issue · 4 comments

Will simplify a lot

class Scorable < ApplicationRecord
  self.table_name = 'players'
end

class Player < Scorable
  belongs_to :team

  counter_culture :team
end

class Team < Scorable
  has_many :players
end

CRUD operations are normally updating players_count.
But If execute Player.counter_culture_fix_counts all counters will be set to 0.

I've reviewed the code and found a mistake in the table name:
On lines 273 and 279 in joins_sql condition for STI and Polymorphic, table name is incorrect, because it must be target_table_alias instead of target_table as it seen in around lines (this is explicitly written on line 243)

Can you put together a PR with that fix and a test case that currently fails on master? Thanks for the report.

This is also affecting me, and due to no action in here, for a long time already, I'm taking it over and will implement the fix shortly.

Thanks @ramonpm. I have an email as task in my inbox since day one, but due to high demand on frontend work can't reach this.

PR open, please review it ☝️