The root of the problem was that one associations returned proxies, not the original/target object.
For now, rather than rewriting the entire associations design, we simply define methods on the owner class that will delegate to the association proxy as necessary, namely the build/create methods. The regular accessor now returns the proxy's target directly. All library-internal calls that expected a proxy to be returned from the accessor now request the proxy through #get_proxy.
This refactoring has some unresolved problems:
Nested attributes callbacks cause linked documents to be saved twice when the owner is saved.
Because of lazy target-class resolution, we cannot proactively define *_keys or *_links accessors on the owner class. In the future we should probably do explicit association-type declarations, e.g. embed_one, link_to_many.
Additionally, the search/reference association type (rarely used) now will handle the new return value from Riak::Client#search.
The root of the problem was that one associations returned proxies, not the original/target object.
For now, rather than rewriting the entire associations design, we simply define methods on the owner class that will delegate to the association proxy as necessary, namely the build/create methods. The regular accessor now returns the proxy's target directly. All library-internal calls that expected a proxy to be returned from the accessor now request the proxy through
#get_proxy
.This refactoring has some unresolved problems:
*_keys
or*_links
accessors on the owner class. In the future we should probably do explicit association-type declarations, e.g.embed_one
,link_to_many
.Additionally, the search/reference association type (rarely used) now will handle the new return value from
Riak::Client#search
.