Undefined method `serializable_hash' for array-Collection of common programming errors
I am using mongoid as my orm, and i call to_json on the result set. The initial implementation works fine, except for the fact that everything is loaded on the fly (as opposed to eager loading)
Simplified schema and code below:
Answer has_many likers
all_answers=Answer.includes(:likers).all.map{|a| a}
all_answer.to_json(:only=>[:text],:include => {:likers=>{:only=>[:_id,:nickname]}})
I started using this great gem (mongoid_eager_loading), and it works great. However, when i call to_json on the result set
all_answers=Answer.includes(:user, :question,:likers,:comments).all.map{|a| a}
all_answer.to_json(:only=>[:text],:include => {:likers=>{:only=>[:_id,:nickname]}})
I will get this error:
undefined method `serializable_hash' for #
This error only happens when I am trying to include an array for example: Answer has_many likers.
I suspect that arrays contained in individual objects does not have the serializable_hash method.
How could I resolve this problem? Any ideas would be greatly appreciated!
Originally posted 2013-11-09 19:45:42.