Fix issues saving belongsToMany associations

Fix several issues related to saving belongsToMany associations. I checked the following things manually and added additional test coverage for:

* Removing all associations.
* Adding associations.
* Removing all but one.
* Creating a new record with no belongsToMany links.

This set of changes resolves #3485.