Use foreign_key for ActiveRecord 4.0.0

The previous fix didn't work for 4.0.0, since it always checked the minor version.