RailsCasts Pro episodes are now free!

Learn more or hide this

Richard Rodgers's Profile

GitHub User: TechRsch

Comments by Richard Rodgers

Avatar

I resorted to using shadow columns in my tables to resole this issue. DBA's might hate it, but I didn't see another choice. That is true especially since I have polymorphic tables that could never be directly referenced any other way within my experience.

Basically, I added columns to the table of name xxshadow. These are used solely to support datatables search and sort.

In my model, I use

after_update :shadow_update.

And, that method is:

  def shadow_update
    # After record is updated, update shadow columns if needed and force an update to write them
    # This actually triggers after create as well, but with correct timing
    # Since all columns are updated to resolve differences, one update should resolve all
    # Incorrectly coded, you can infinitely loop on the update
    if [self.yrshadow, self.mkshadow, self.mdshadow, self.coshadow, self.stshadow] != [self.year, self.make, self.model, self.color, self.status]
      self.yrshadow = self.year
      self.mkshadow = self.make
      self.mdshadow = self.model
      self.coshadow = self.color
      self.stshadow = self.status
      self.save!
    end