Note that there are some explanatory texts on larger screens.

plurals
  1. POforeign-key on a table not in the database, with ORM
    primarykey
    data
    text
    <p>I have a static table <code>entry</code> that's shared by several databases/website. By static, I mean the data is read but never updated by the websites. Currently, all websites are served from the same server but that may change.</p> <p>I want to minimize the need for creating/maintaining this table for each of the websites, so I thought about turning it to a variable that's stored in a shared library that all websites have access to. </p> <p><strong>The problem is I use an ORM and use foreign key constraints to ensure referential integrity of the ids used from that static table,</strong> so by removing that table out of the MySQL database into a variable, how can I still get referential integrity for the ids referenced from that table? Do I have to do it entirely programmatically or is there a trick to still treat the data as if coming from a real db table. </p> <p>My database definition (using Propel) originally looked like this, where the <code>refer</code> table had a field <code>linkto</code> that was referencing the <code>id</code> of the <code>entry</code> table. Now that the <code>entry</code> table is in code, I can't do the foreign-key trick any more, or can I somehow get the same effect?</p> <pre><code> &lt;table name="entry"&gt; &lt;column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" /&gt; &lt;column name="title" type="VARCHAR" size="500" required="true" /&gt; &lt;/table&gt; &lt;table name="refer"&gt; &lt;column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" /&gt; &lt;column name="linkto" type="INTEGER"/&gt; &lt;foreign-key foreignTable="entry"&gt; &lt;reference local="linkto" foreign="id" /&gt; &lt;/foreign-key&gt; &lt;/table&gt; </code></pre> <p><strong>And of course are these any other efficient ways to do the same thing? I just don't want to have to repeat that table for several websites.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload