Fix *_ids method for has_many with primary_key

A `has_many` association with a custom `primary_key` was using the wrong primary key field name to find the list of associated IDs.

See https://github.com/rails/rails/issues/14439 for details.
Good call, Joe. I've extracted this.