Kim Bachman wrote:
Message

To make things worse, I need the ability to add/remove properties from the item data on a per item basis at run time.  The item data could include one or more of hundreds of properties.
 
ItemView
    Item[Name:S,Description:S,Number:I...]
        ItemDataView
            ItemData[Date:I,Time:I,Style:I,Size:I...]
            ...
            ItemData[Date:I,Time:I,Style:I,Size:I...]
 
    Item[Name:S,Description:S,Number:I...]
        ItemDataView
            ItemData[Date:I,Type:I,Length:I,Color:I...]
            ...
            ItemData[Date:I,Type:I,Length:I,Color:I...]
   
1. Is this possible in Metakit?
Yes.  Get rid of ItemView and have Item in different tables.  Let's assume that in your table "Name" is unique across all items.  You will need some unique identifier for the following technique to work.  If name as unique we can generate an "items" table which knows which underlying table a given item lives in.  The underlying tables can have different properties and subviews but all should have an unique column Name.

The idea is when looking up an object first find the name in the items table.  From the items table find out the name of the subtable, retrieve this view and then look up Name in the subtable.

You'll have to forgive my python style pseudo code here. 

itemtable = st.getas("items[Name:S,table:S]")
itemtype1 = st.getas("itemtype1[Name:S.Description:S,Number:I...,data[Date:I,Time:I,Style:I,Size:I]")
itemtype2 = st.getas("itemtype2[Name:S.Description:S,Number:I...,data[Date:I,Type:I,Length:I,Color:I...]")

# we'll create two objects named "object1" and "object2" that live in the seperate tables itemtype1 itemtype2
itemtable.append(("object1", "itemtype1"))
itemtable.append(("object2", "itemtype2"))

# add some data to the objects
index = itemtype1.append(("object1", ...))
# add some properties to the subview
itemtype1[index].data.append(record1))
itemtype1[index].data.append(record2))

index = itemtype2.append(("object2", ...))
...

now the dispatch method to find the appropriate subtable

The dispatcher finds a given item with name Name
from itemtable and retrieve the appropriate row from the subtables

#first find out which table belongs to the item
index = itemtable.find(Name=Name)
if index == -1: Error, cannot find item
row = itemtable[index]
#retrieve the proper table
table = st.view(row.table)
# the subtables can be restructured on the fly with new properties ect...
# find the proper row
index = table.find(Name=Name)
if index == -1: Error, Name doesn't exist in the table!
# get the row
row = table[index]
# play with the row :)
for data in row.data:
      ...


 

Reply via email to