I would write it the other way around, you already have all ids without going into the smart proxies table..
e.g.

``` ruby
smart_proxies << subnet.dhcp_id << subnet.tftp_id << subnet.dns_id if subnet
smart_proxies << domain.dns_id if domain
...