Subject | Re: Design question for "attributed instances" |
---|---|
Author | Ali Gökçen |
Post date | 2005-10-22T11:32:21Z |
Hi Heiko,
Sorry it was my fault about my perfect(!) english knowladge plus
unstable-fast OCR of my brain.
from item
where cat_id=:selected_cat_id
and att_id in (:selected_att_id1,:selected_att_id2 ...)
My design was most flexable, you can define any item with any
catagory and attribute combination.
your examples was about each items have only one catagory and
attribute.
if your object items have more than one category or attributes,
then you need to define other referance tables..
CREATE TABLE CATEGORY (
ID INTEGER PRIMARY KEY ,
NAME VARCHAR(64) NOT NULL UNIQUE
);
CREATE TABLE ATTRIBUTE (
ID INTEGER PRIMARY KEY,
NAME VARCHAR(64) NOT NULL UNIQUE
);
CREATE TABLE CATEGORY_ATRIBUTE (
ID INTEGER PRIMARY KEY,
CAT_ID INTEGER NOT NULL REFERENCES CATEGORY(ID),
ATT_ID INTEGER NOT NULL REFERENCES ATTRIBUTE(ID),
UNIQUE(CAT_ID,ATT_ID)
);
-- You can predefine category-attribute relations with this table
to force usage of them
CREATE TABLE OBJECT (
ID INTEGER PRIMARY KEY,
NAME VARCHAR(64) NOT NULL UNIQUE
);
CREATE TABLE OBJECT_DETAIL (
ID INTEGER PRIMARY KEY,
OBJECT_ID INTEGER NOT NULL REFERENCES OBJECT(ID),
CAT_ATT_ID INTEGER NOT NULL REFERENCES CATEGORY_ATTIBUTE(ID)
);
CREATE TABLE ITEM (
ID INTEGER PRIMARY KEY,
OBJECT_ID INTEGER NOT NULL REFERENCES OBJECT(ID),
NAME VARCHAR(64) NOT NULL UNIQUE
);
You can do what you want to do with this tables.
Regards.
Ali
Sorry it was my fault about my perfect(!) english knowladge plus
unstable-fast OCR of my brain.
> Where for instance is the attribute value?select name
> How would you search for an "instance" of a category
> with specific attribute values?
from item
where cat_id=:selected_cat_id
and att_id in (:selected_att_id1,:selected_att_id2 ...)
My design was most flexable, you can define any item with any
catagory and attribute combination.
your examples was about each items have only one catagory and
attribute.
if your object items have more than one category or attributes,
then you need to define other referance tables..
CREATE TABLE CATEGORY (
ID INTEGER PRIMARY KEY ,
NAME VARCHAR(64) NOT NULL UNIQUE
);
CREATE TABLE ATTRIBUTE (
ID INTEGER PRIMARY KEY,
NAME VARCHAR(64) NOT NULL UNIQUE
);
CREATE TABLE CATEGORY_ATRIBUTE (
ID INTEGER PRIMARY KEY,
CAT_ID INTEGER NOT NULL REFERENCES CATEGORY(ID),
ATT_ID INTEGER NOT NULL REFERENCES ATTRIBUTE(ID),
UNIQUE(CAT_ID,ATT_ID)
);
-- You can predefine category-attribute relations with this table
to force usage of them
CREATE TABLE OBJECT (
ID INTEGER PRIMARY KEY,
NAME VARCHAR(64) NOT NULL UNIQUE
);
CREATE TABLE OBJECT_DETAIL (
ID INTEGER PRIMARY KEY,
OBJECT_ID INTEGER NOT NULL REFERENCES OBJECT(ID),
CAT_ATT_ID INTEGER NOT NULL REFERENCES CATEGORY_ATTIBUTE(ID)
);
CREATE TABLE ITEM (
ID INTEGER PRIMARY KEY,
OBJECT_ID INTEGER NOT NULL REFERENCES OBJECT(ID),
NAME VARCHAR(64) NOT NULL UNIQUE
);
You can do what you want to do with this tables.
Regards.
Ali