Implement required #encode_with

While running the spec `ARCONN=mysql2 ruby -v -Itest
test/cases/yaml_serialization_test.rb`
the following warning shows up:
`implementing to_yaml is deprecated, please implement "encode_with"`
Move #encode_with to Relation
Merge pull request #16183 from goddamnhippie/fix-psych-warning

Implement required #encode_with