title: Is this the right way to passively assign categories to an entity
body: <p>I am trying to design a database which can be used to 'passively' identify (and optionally assign) any/all categories that an object fits into. The below is the way I'm currently implementing it but not having done this before, I wanted to see if anyone has a better idea of how to go about doing it. I am using Symfony with MySQL and Doctrine.</p>
  
  <p><strong>1/. Tables that define the objects:</strong></p>
  
  <p>An <kbd>Element</kbd> table that contains features that an animal could have. This table will evolve over time - eg as animals that have wings are added:</p>
  
  <pre><code>ID NAME   CRITERIA
  1  Leg    0-100
  2  Arm    0-2
  3  Pouch  Boolean
  4  Horn   0-2
  </code></pre>
  
  <p>An <kbd>Animal</kbd> table that give individual information on each animal in the database:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>An <kbd>Identity</kbd> table to assign which <kbd>Elements</kbd> are assigned to each <kbd>Animal</kbd>:</p>
  
  <pre><code>ANIMALID  ELEMENTID COUNT DESCRIPTION
  1         1         4     
  1         4         0                       
  2         1         2     
  2         2         2     
  2         3         True                    // Female kangaroo has a pouch
  3         1         2     Strong hind legs
  3         2         2     
  3         3         False                   // Male kangaroo has no pouch
  </code></pre>
  
  <hr>
  
  <p>The above I am clear with. However, I want to be able to passively identify/assign the categories that the current object meets the required criteria for. Ideally, as the user is filling in the form to create a new <kbd>Animal</kbd> they would be able to see a list of which categories they are currently meeting the criteria for as they add/remove <kbd>Element</kbd> (eg Cow, Mammal, Bovine, Quadruped).</p>
  
  <hr>
  
  <p>To continue the example:</p>
  
  <p><strong>2/. Tables that define the categories:</strong></p>
  
  <p>A <kbd>Class</kbd> table to define the required attributes of a category:</p>
  
  <pre><code>ID NAME           WEIGHTMIN WEIGHTMAX HEIGHTMIN HEIGHTMAX AgeMax
  1  Adult Cow      220       1000      .         200       50
  2  Kangaroo       .         100       .         .         .
  </code></pre>
  
  <p>A <kbd>Class_Feature</kbd> table which additionally defines mandatory features of a <kbd>Class</kbd> through a one-to-many association that are additionally required. Note: <code>GROUPID</code> identifies groups of required features and <code>SUBGROUPOF</code> identifies if the options are nested under an additional mandatory requirement (such as with male/female cows having horns):</p>
  
  <pre><code>CLASSID GROUPID SUBGROUPOF ELEMENTID  GENDER MIN   MAX
  1       1       .          2          .      0     0        // A cow can't have any 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 
  </code></pre>