Update ORM.php

Enables the use of foreign keys as a unique_base, 

closes #827
closes #839