riak-ripple / ripple

A rich Ruby modeling layer for Riak, Basho's distributed database
Other
618 stars 152 forks source link

Address #197, 'nil is not nil'. #306

Closed seancribbs closed 10 years ago

seancribbs commented 12 years ago

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:

  1. Nested attributes callbacks cause linked documents to be saved twice when the owner is saved.
  2. 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.