-
Notifications
You must be signed in to change notification settings - Fork 13
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
json_fields: expose all fields plus additional methods #12
Comments
How do you already expose the existing fields today? In order to do caching this gem will need to know about each field, notably whether it's a json_fields \
attributes: { select: :all }, # maybe attributes: :auto, etc.?
something_else: { ... } |
Before your gem I was doing 'as_document.to_json'. Your comments gave me an idea. I could make a self.attributes method that simply collected all the methods in the document. Is the what you were suggesting? Mark Silverberg On Apr 5, 2013, at 7:47 AM, "Daniel Doubrovkine (dB.)" [email protected] wrote:
|
Not really. Again, mongoid_cached_json needs to know about the actual attributes, its implementation keeps all kinds of structures around that it looks at when overriding |
Got it -- that " |
So is there an equivalent of |
@mping Care to elaborate? |
Sure, the rails docs state that you can indicate methods to be called when generating the json: http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html here's the relevant example:
is there an equivalent for this? AFAIK you can only indicate what fields you want. I am also having trouble understanding the lifecycle of the json cache, ie, if I should manually expire an object or not. My ideal use case would be that I would just include the gem, I wouldn't even need to specify the json_fields (btw this causes an error) and my |
Your ideal workflow would be a good feature request (this thread is that feature request): something that automatically figures out which fields to include in the JSON. This is just not implemented. Currently you have to declare the JSON fields. There's no equivalent of specifying what you want in the JSON at runtime, you have to do this through a You don't have to manually expire anything, when you include the module in a Mongoid document cache will expire on changes. |
I don't mind declaring the
this would cover 99% of my needs :) |
The I am open to evolving both of these things, but I suspect the implementation is far from trivial. |
I haven't looked at the code, so can't really say there's a way to implement custom |
It's all here. |
I'm new to using mongoid-cached-json but so far it seems like exactly what I need - thank you!
I have a fairly complex model and I want
.to_json
to expose all of its key/values just as it did before I added mongoid-cached-json to the mix but also two methods (:definition => :method
). When I do the following,.to_json
starts to only expose the two defined methods.Bottom line: trying to have it just add the defined fields to
.to_json
and not replace the existing contents. Ideas? Is that within scope of this project?Many thanks in advance!
The text was updated successfully, but these errors were encountered: