how about
```ruby
subhostgroups = Hostgroup.where(:id => hostgroup_ids).map(&:subtree).flatten
```