Fixes race condition in resources

See #1378.
I wouldn't necessarily call this a hack. This is the correct way to make groups of objects in a relational database: have a single object in another table which signifies the group, and have group members point to it.

Really, the original group_id system was a hack. Well, really, the entire resources system is a hack.