In Rails application I want to be able to store schema-less objects — JSON data structure, that could have different structure from object to object, or for the same object at different times.
With ElasticSearch I can do this. However I would like to be use some kind of ORM with Rails for this.
Tried to do some testing with Tire tutorial, doing this in Rails console:
>>> c = Article.new :title =>'New article', :content => { :a => 'a', :b => 'b'}
I can see that content data stored as serialized YAML:
>> Article.last.content
=> "---\n:a: a\n:b: b\n"
This will require parsing search result to JSON, which is not a problem. But main question: will I be able to search inside serialized data? Is there a way to return attribute names from arbitrary structured data (like Object.keys)?
If not Tire, is there other solutions to do this?
Not really sure what you’re up to here, but Tire does come with a drop-in replacement for ActiveRecord integration, just
include Tire::Model::Persistencein your class. You may also define properties (with mappings, type casting, default values, etc):The Tire README and integration tests have all the info.
Of course you’re able to search inside the
contentattribute — it’s just a matter of proper mapping.If you’re after some specific behaviour, please update your question…