Forum BigDB Any way to get a DatabaseObject to remove itself?

Discussion and help relating to the PlayerIO database solution, BigDB.

Any way to get a DatabaseObject to remove itself?

Postby CoderBrandon » May 20th, 2011, 3:12 am

I have a DatabaseArray of DatabaseObjects and each of those objects don't have a reference back to the parent array (that I'm aware of).

Is there a way for a DatabaseObject to remove itself?
CoderBrandon
 
Posts: 6
Joined: April 22nd, 2011, 3:33 am
Location: Savannah, GA, USA

Re: Any way to get a DatabaseObject to remove itself?

Postby Oliver » May 20th, 2011, 11:09 am

What do you mean by "remove itself"?

if you have: obj.something.another and you want to remove another, you have to do it via obj.Remove("something.another")


Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Any way to get a DatabaseObject to remove itself?

Postby CoderBrandon » May 20th, 2011, 5:22 pm

I don't think there is a way currently, but I'll give my specific example and see if you can give me some feedback on my approach.

I have a table "Areas" with structure:
Code: Select all
areaKEY={
   size:{
      x:40,
      y:40
   },
   resources:{
      0:{
         position:{
            x:34,
            y:20
         },
         guid:"dda0b115-5016-4e11-9f5d-3c9909794c09",
         amount:2,
         resourceKey:"MetalScrap"
      },
      1:{
         position:{
            x:27,
            y:7
         },
         guid:"b5f9d643-88ed-411d-a90f-7703a91db35d",
         amount:1,
         resourceKey:"GlassScrap"
      }, etc


On my server I set the resources part to a DatabaseArray and loop over all the objects and pass them into an object constructor for AreaResource(DatabaseObject areaResourceDBO).

Code: Select all
//class variable of room
private SortedDictionary<string, AreaResource> areaResources = new SortedDictionary<string, AreaResource>();

//on the callback from loadRange
DatabaseArray allResources = dbo.GetArray("resources");
foreach (DatabaseObject singleResource in allResources) {
   AreaResource temp = new AreaResource((DatabaseObject)(singleResource));
   areaResources.Add(temp.guid, temp);
}


From within each instance AreaResource, I have logic that determines if it should be removed, and I'd love to be to call:
Code: Select all
//class AreaResource

//class variable reference to BigDB object
private DatabaseObject dbo;

//inside some logic to determine removal status
dbo.remove()


The only option I think I have is to tell the room to delete it, since the room has a reference to the DatabaseArray that it's attached to.

Advice?
CoderBrandon
 
Posts: 6
Joined: April 22nd, 2011, 3:33 am
Location: Savannah, GA, USA

Re: Any way to get a DatabaseObject to remove itself?

Postby Oliver » May 24th, 2011, 3:58 pm

You're right, there is no way to get parent information or get it to remove itself from parent. You have to call .Remove() on the parent object manually.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to BigDB



cron