Well, I tried to do so, but it seems like the package_id for the objects is not the same package_id for a community. What I did to solve this issue is a little bit different: I am "walking up" the table. I got the context_id and put it in the object_id. Then I got the context_id for the new object and put it in the object_id. It's like climbing up the stairs, until I find the object_type like dotlrn_community.
The problem here is about the performance. I'm doing recursive searchs in a huge table like acs_objects, and this is not a nice thing to do. What I could find out is that I can improve the performance of my query using the tree_sortkey. However, I found another problem here: it just doesn't work for some objects. For forums it works, but for other objects, like file-storage folders it does not work. It seems like the tree_sortkey of the file-storage object is related to its parent folder, but it never gets to the community. So, I'm out of ideas to improve the performance. Any idea?