Improves dependent restrict in ActiveRecord 4 and backports to AR 2/3