JackDanger / permanent_records

Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid
https://jdanger.com
MIT License
272 stars 64 forks source link

Fix reflection cache #90

Open joel opened 8 years ago

joel commented 8 years ago

I've a trouble with using attribute accessor _reflections this bring to me wrong associations, and it fixed when I use directly the method reflections but test suite break, maybe @drakmail can have a look, you made this PR https://github.com/JackDanger/permanent_records/pull/74

Right now I can't upgrade to the 4.2.7

drakmail commented 8 years ago

Really seems that counter_cache methods is broken, I'll try to take a look on this issue at this week

IngusSkaistkalns commented 7 years ago

I have not checked if its true, but this would also fix HABTM issues, because _reflections includes HABTM association that gets generated dynamically, while this assoc does not appear when reflect on records class.

class Article
  has_and_belongs_to_many :article_classes
end
Article.new._reflections['article_article_classes'] # => ActiveRecord::Reflection::HasManyReflection: @name=:articles_article_classes

Next this will happen => https://github.com/JackDanger/permanent_records/blob/master/lib/permanent_records.rb#L110, and so we get undefined method articles_article_classes called.

flanger001 commented 5 years ago

I realize I'm awakening what may be a dead thread here, but this is something I'm finding also and changing _reflections to PermanentRecords.dependent_permanent_reflections(self.class) works for me as well.