On Sunday, January 2, 2011 at 3:29 PM, Jaron wrote:
I just started using MongoMapper (and mongodb in general) a few days
ago and so far am really enjoying it!
Today I ran into an issue with how the Proxy class behaves when the
association is supposed to be nil. Effectively what you end up with
is a Proxy class pretending to be nil in some aspects, but not in
every way.
Say you have the following classes:
class User
include MongoMapper::Document
end
class Comment
include MoongoMapper::Document
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en
Thanks for doing all this work Jaron, I'm all in favor of returning true nil's.
However, I very much like the consistent .build syntax in MM. How about returning a nil class that has build and other appropriate methods defined on it?
a = nil
def a.build
"build logic here"
end
a.build # => "build logic here"
if a
"this isn't reached"
end
Ruby magic! As "hackish" as it seems, I think it's less likely to cause bugs than a proxy pretending to be nil, and it still retains the nice syntax you get from the proxy.
Brian Hempel