{"id":488,"date":"2022-08-30T15:02:11","date_gmt":"2022-08-30T15:02:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/undefined-method-serializable_hash-for-array-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:11","modified_gmt":"2022-08-30T15:02:11","slug":"undefined-method-serializable_hash-for-array-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/undefined-method-serializable_hash-for-array-collection-of-common-programming-errors\/","title":{"rendered":"Undefined method `serializable_hash&#39; for array-Collection of common programming errors"},"content":{"rendered":"<p>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)<\/p>\n<p>Simplified schema and code below:<\/p>\n<pre><code>Answer has_many likers \n\nall_answers=Answer.includes(:likers).all.map{|a| a}\nall_answer.to_json(:only=&gt;[:text],:include =&gt; {:likers=&gt;{:only=&gt;[:_id,:nickname]}})\n<\/code><\/pre>\n<p>I started using this great gem (mongoid_eager_loading), and it works great. However, when i call to_json on the result set<\/p>\n<pre><code>all_answers=Answer.includes(:user, :question,:likers,:comments).all.map{|a| a}\nall_answer.to_json(:only=&gt;[:text],:include =&gt; {:likers=&gt;{:only=&gt;[:_id,:nickname]}})\n<\/code><\/pre>\n<p>I will get this error:<\/p>\n<pre><code>undefined method `serializable_hash' for #\n<\/code><\/pre>\n<p>This error only happens when I am trying to include an array for example: Answer has_many likers.<\/p>\n<p>I suspect that arrays contained in individual objects does not have the serializable_hash method.<\/p>\n<p>How could I resolve this problem? Any ideas would be greatly appreciated!<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:45:42. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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=&gt;[:text],:include =&gt; {:likers=&gt;{:only=&gt;[:_id,:nickname]}}) I started using this great gem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-488","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=488"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/488\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}