mysql - Is this the right way to passively assign categories to an entity -
i trying design database can used 'passively' identify (and optionally assign) any/all categories object fits into. below way i'm implementing not having done before, wanted see if has better idea of how go doing it. using symfony mysql , doctrine.
1/. tables define objects:
an element table contains features animal have. table evolve on time - eg animals have wings added:
id name criteria 1 leg 0-100 2 arm 0-2 3 pouch boolean 4 horn 0-2
an animal table give individual information on each animal in database:
id name gender weight dob 1 gertrude f 450 2010-01-01 2 shiela f 200 2008-01-01 3 bruce m 250 2012-01-01
an identity table assign elements assigned each animal:
animalid elementid count description 1 1 4 1 4 0 2 1 2 2 2 2 2 3 true // female kangaroo has pouch 3 1 2 strong hind legs 3 2 2 3 3 false // male kangaroo has no pouch
the above clear with. however, want able passively identify/assign categories current object meets required criteria for. ideally, user filling in form create new animal able see list of categories meeting criteria add/remove element (eg cow, mammal, bovine, quadruped).
to continue example:
2/. tables define categories:
a class table define required attributes of category:
id name weightmin weightmax heightmin heightmax agemax 1 adult cow 220 1000 . 200 50 2 kangaroo . 100 . . .
a class_feature table additionally defines mandatory features of class through one-to-many association additionally required. note: groupid
identifies groups of required features , subgroupof
identifies if options nested under additional mandatory requirement (such male/female cows having horns):
classid groupid subgroupof elementid gender min max 1 1 . 2 . 0 0 // cow can't have arms 1 2 1 4 m 1 2 // male cows have horns 1 2 1 4 f 0 0 // female cow can not have horns 2 1 . 3 m 0 0 2 1 . 3 f 1 1
Comments
Post a Comment