{"id":713,"date":"2022-08-30T15:05:56","date_gmt":"2022-08-30T15:05:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/how-to-merge-2-object-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:56","modified_gmt":"2022-08-30T15:05:56","slug":"how-to-merge-2-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-merge-2-object-collection-of-common-programming-errors\/","title":{"rendered":"How to merge 2 object-Collection of common programming errors"},"content":{"rendered":"<p>pass the ids to <code>find<\/code> in a single call like<\/p>\n<pre><code>@posts = Post.find([1, 2])\n<\/code><\/pre>\n<p>Be warned that if there is no post with ID=1 or ID=2, this will raise an error. If you dont this, use <code>where<\/code> or <code>find_all_by_id<\/code><\/p>\n<pre><code>@posts = Post.where(id: [1, 2])\n@posts = Post.find_all_by_id([1, 2])\n<\/code><\/pre>\n<p>The main difference between the 2 is that you can chain other queries with <code>where<\/code> whereas <code>find_all_by_id<\/code> already returns an array so you can&#8217;t chain queries.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:42:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>pass the ids to find in a single call like @posts = Post.find([1, 2]) Be warned that if there is no post with ID=1 or ID=2, this will raise an error. If you dont this, use where or find_all_by_id @posts = Post.where(id: [1, 2]) @posts = Post.find_all_by_id([1, 2]) The main difference between the 2 is [&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-713","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/713","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=713"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/713\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}