The polymorph spell states, in part:
The target’s game statistics, including mental ability scores, are replaced by the statistics of the chosen beast. It retains its alignment and personality.
Does retaining its personality suffice to let it remember who its allies are? Even if transformed into something stupid like a T-rex? What does it even mean for a beast with Int 2 to have someone's "personality"?