Only show loaded keys when inspecting. If key is requested that has not been loaded, maybe we should perform query for it? This would make it so that identity map could keep track of models with partially loaded keys as well instead of ignoring them.
Also along these lines we should not add dynamic keys to the class, but instead just to the instance.
I can see it both ways... I also posted about this: http://technicaldebt.com/?p=952
If the key was a mistake, remove it.
If the key was added for an instance or three... but it is not in the class, should it be revealed or hidden?
I can see MongoDB opting for the default to show the superset. It would be maddening to know you added some documents with certain keys, only to not ever be able to find them! Also, this allows you to be much more dynamic about storing new key/value pairs on the fly and being able to always know what keys are available. (More akin to RDF "loose" data schemas.)
I can also see wanting to know only what is in the "official" class model.
So, I don't think it is an either / or thing.
I'm working on a changeset right now that addresses both of these issues.
Okay, so after spending an afternoon on it, I'm thinking the following:
implicit_schema(bool = true)
strict_keys(bool = false)
The implicit_schema(true) and strict_keys(false) defaults would behave the same way that documents currently behave today - keys are aggregated on the class, and undefined keys are handled automatically.
Setting implicit_schema(false) would move key creation for unknown fields from the class to the instance. This means that a given instance would have accessors for the unknown keys, but that they wouldn't become a permanent part of the model schema.
Setting strict(true) would raise an exception upon attempting to handle an attribute that is not defined on the model.
This could use some alternate interface, like schema(:strict => <bool>, :implicit => <bool>) for more condensed application.
schema(:strict => <bool>, :implicit => <bool>)