# group\_by missing items

**URL:** <https://discuss.rubyonrails.org/t/group-by-missing-items/40480>\
**Category:** rubyonrails-talk\
**Created:** [March 16, 2009, 11:30am UTC](https://discuss.rubyonrails.org/t/group-by-missing-items/40480 "2009-03-16T11:30:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [March 16, 2009, 11:30am UTC](https://discuss.rubyonrails.org/t/group-by-missing-items/40480/1 "2009-03-16T11:30:05Z")

</div>

I use the acts\_as\_tree plugin, and I try to display a list of the elements w group\_by

in my controller ... &nbsp;&nbsp;&nbsp;&nbsp;companies = Company.find :all, conditions =\> Company.visible\_by (User.current), :include =\> :parent &nbsp;&nbsp;&nbsp;&nbsp;respond\_to do |format| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@company\_tree = companies.group\_by {|p| p.parent || p} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

I have the company ids : [1, 2, 3, 4, 5, 6] with the following tree structure : 1 children -\>[2 , 3] 2 -\> children [4, 5, 6] and 3 has no child

the companies.group by gives me correctly an Hash with [key company 1 -\> value [company 2, company 3] key company 2 -\> value [company 4, company 5, company 6] ]

but no key company 3 ... is it because the group is empty (no child) ... how can I get the key company 2, with an empty array as value ? is it possible ?

thanks for your help
