Fixed bug introduced in Rails upgrade that caused reference trees to be modified