Fix ActiveRecord::MissingAttributeError with a solution that has better performance.