-
Notifications
You must be signed in to change notification settings - Fork 792
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
as_json only: [...attributs...], methods: [...methods list...] => callback update_document does not update "methods values" in ES #40
Comments
Implement you own callback for |
ok. It would be nice if we could say 'if this attribute changes, then save this method at the same time' |
ok. thank you. We'l try to help with a solution if I find something interesting. |
…serialized during update Previously, the `update_document` method simply intercepted the changes to the model, via the `@__changed_attributes` variable, and used these directly. This caused models with a custom serialization method to be incorrectly serialized, namely unwanted attributes were added. This patch looks for `as_indexed_json` defined on the model, and when it finds it, filters the changed attributes through the keys. Closes #75 Related: * #59 * #57 * #52 * #40 * #37 * #5
@alotela The linked commit should fix your issue. |
If I'm right, it just checks for attributes I really want to put into ES. My problem is that when I use methods array in as_indexed_json, they are not updated. It's not about unwanted attributes.
2/ In my concern or model, I had this to know the methods I need to "refresh" depending on changed attributes:
last_connection_at, lat, png are my model's attributes
Works perfectly! |
@alotela You shouldn't override
Yes, see #5 for a discussion about that. Just implement your own hooks for indexing, that's it, really. |
I totally agree that overriding update_document is not the right way to do. I personally think this problem should be managed by the gem easily... And defining a method to match changed_attributes and "changed_methods" looks good for me. It allows the gem to update only changed data. What do you think ? ;) |
I still think the cleanest way is to simply define your own indexing routines, in concert with your own serialization routines. The default callbacks are just that -- defaults for convenience. |
Hi,
I have a mapping with methods and attributes:
def as_indexed_json options={}
as_json only: ['id', 'banned','birthday'],
methods: ['method1', 'method2', methodn']
end
when I want to update a document, only changed attributes are saved in ES, not methods...
Looking at indexing.rb code, this seems normal:
def update_document(options={})
if changed_attributes = self.instance_variable_get(:@__changed_attributes)
client.update(
{ index: index_name,
type: document_type,
id: self.id,
body: { doc: changed_attributes } }.merge(options)
)
else
index_document(options)
end
end
so, how can I autosave "methods" values to ES when they are changedat the same time as attributes ?
The text was updated successfully, but these errors were encountered: