Cache the value of `changed_attributes` when calling `changes_applied`

`changes_applied` calles `changes`, which will call `changed_attributes`
multiple times in a loop. This method actually performs work now, so we
should cache the results while looping over it when we know it cannot
change.
Merge pull request #16646 from sgrif/sg-perf-regression

Cache the value of `changed_attributes` when calling `changes_applied`
added primary_key option documentation for belongs_to association

fixes issue #16698