Forum: Ruby on Rails group_by missing items

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2009-03-16 12:34
(Received via mailing list)
I use the acts_as_tree plugin, and I try to display a list of the
elements w group_by

in my controller
...
    companies = Company.find :all, conditions => Company.visible_by
(User.current),  :include => :parent
    respond_to do |format|
      format.html {
        @company_tree = companies.group_by {|p| p.parent || p}
      }

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
This topic is locked and can not be replied to.