This looks incredibly sketchy -- does it not work without it?  That suggests that the Distance.unit_attname, or Field.units_name method isn't working to me, rather than it always returns metres.