Reworked foreign key support for ActiveRecord 4.0, 4.1 and 4.2