-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nil is not behaving like nil #197
Comments
This is due to the fact that ripple is using a proxy for the association. It is proxying to nil, but the proxy itself is not nil. You can check nil with I agree this is a gotcha, but I'm not sure what the solution should be. |
Feels like there could be a special-case/guard on the accessor method if the target is |
Another thing I noticed about the snippet is that the target is not actually nil because the link still exists, even though the object on the other side doesn't. There is no referential integrity. |
I like this idea. I've used the I was actually just bitten last night by a bug due to a nil-proxy being truthy. I can take a look at fixing this the next time I'm working on ripple. One concern, though: once we change the association accessor to return nil, you can't call methods on it anymore (like |
@myronmarston I think ActiveRecord went the route of |
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`.
Whenever I have a one linked association that is empty, the nil value returned is not the correct nil. Normally nil has an object_id equal to 4. This nil has an object_id that is something else. You can emulate the problem by putting the following in your associations spec:
This bug renders things like "if" and "unless" useless. Even the && and || operators treat this nil as truthy.
The text was updated successfully, but these errors were encountered: