title: Can a foreign key have a constant instead of a field name? Relate FK to STI subclass
body: <p><strong>Setup</strong></p>
  
  <p>So here's a scenario which I'm finding is rather common once you decide to play with STI (Single Table Inheritance). </p>
  
  <p>You have some base type with various subtypes. </p>
  
  <ul>
  <li>Person &lt; (Teacher,Student,Staff,etc)</li>
  <li>User &lt; (Member,Admin)</li>
  <li>Member &lt; (Buyer,Seller)</li>
  <li>Vehicle &lt; (Car,Boat,Plane)</li>
  <li>etc.</li>
  </ul>
  
  <p>There are two major approaches to modelling that in the database:</p>
  
  <ul>
  <li>Single Table Inheritance
  <ul>
  <li>One big table with a type field and a bunch of nullable fields</li>
  </ul></li>
  <li>Class Table Inheritance
  <ul>
  <li>One table per type with shared PK (FK'd from the children to the parent)</li>
  </ul></li>
  </ul>
  
  <p>While there are several issues with STI, I <em>do</em> like how it manages to cut down on the number of joins you have to make, as well as some of the support in frameworks like Rails, but I am running into an issue on how to relate subclass-specific tables.</p>
  
  <p>For example:</p>
  
  <ul>
  <li>Certifications should only reference Teacher-Persons</li>
  <li>Profiles should only reference Member-Users</li>
  <li>WingInformation should be not be related to a car or boat (unless you are Batman maybe)</li>
  <li>Advertisements are owned by Seller-Members not Buyer-Members</li>
  </ul>
  
  <p>With CTI, these relationships are trivial - just slap a Foreign Key on the related table and you're done:</p>
  
  <pre><code>ALTER TABLE advertisements
   ADD FOREIGN KEY (seller_id) REFERENCES sellers (id)
  </code></pre>
  
  <p>But with STI, the similar thing wouldn't capture the subtype restriction.</p>
  
  <pre><code>ALTER TABLE advertisements
    ADD FOREIGN KEY (seller_id) REFERENCES members (id)
  </code></pre>
  
  <p>What I would like to see is something like:</p>
  
  <pre><code>* Does not work in most (all?) databases *
  ALTER TABLE advertisements
    ADD FOREIGN KEY (seller_id, 'seller') REFERENCES members (id, type)
  </code></pre>
  
  <p>All I have been able to find is a dirty hack requiring adding a computed column to the related table:</p>
  
  <pre><code>ALTER TABLE advertisements
    ADD seller_type VARCHAR(20) NOT NULL DEFAULT 'seller'
  ALTER TABLE advertisements
    FOREIGN KEY (seller_id, seller-type) REFERENCES members (id, type)
  </code></pre>
  
  <p>This strikes me as odd (not to mention inelegant).</p>
  
  <p><strong>The real questions</strong></p>
  
  <p>Is there a RDBMS out there which will allow me to do this?</p>
  
  <p>Is there a reason why this isn't even possible?</p>
  
  <p>Is this just one more reason why NOT to use STI except in the <em>most trivial</em> of cases?</p>