Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate facsimile entries for all records stemming from a single reocrd within a parent table
    primarykey
    data
    text
    <p>I have a database which below object level is self-constructing or at least it creates and alters sibling tables as and when required and creates a relation between the table and the objects table.</p> <pre><code>Structure: &lt;Projects&gt; - id _______ &lt;collections&gt; .... | - id ______________ &lt;objects&gt; &lt;some_object&gt; |_____&gt; - project_id | - id___________________&gt; .... |___&gt; - collection_id | &lt;some_other_object&gt; .... |___&gt; | .... </code></pre> <p>Can anyone suggest a succinct method of creating a copy of each entry linked to a give collections record, which in turn would be linked to a new collections record?</p> <p>Each of the tables have an object_id column which has a foreign key constraint to objects.id, the rest of the table structure is likely to differ.</p> <p>Take the following example:</p> <pre><code>|Collections| ------------------ | id | Title | ------------------ | 1 | Col1 | | 2 | Col2 | ------------------ |Objects| -------------------------------------------- | id | Collection_id | Object Type | --------------------------------------------| | 1 | 1 | Classification | | 2 | 1 | Space | | 3 | 2 | Classification | --------------------------------------------| </code></pre> <p>The self-constructing element creates a table with the name of the Object type. This won't affect the approach but should make the next part of the example a less confusing.</p> <pre><code>|Classification (or other self-constructing table)| ------------------------------------------------------------ | id | object_id | Some column | ,,, | ,,, | --------------------------------------------|--------------- | 1 | 1 | val | | 2 | 1 | val | | 3 | 2 | val | --------------------------------------------| </code></pre> <p>So with the above records say we were looking to create a facsimile of "Col1" from collections and its dependents, we'll say the new collection.id = 3.</p> <p>The resulting table structure would be as follows.</p> <pre><code>|Collections| ------------------ | id | Title | ------------------ | 1 | Col1 | | 2 | Col2 | | 3 | Col1 | ------------------ |Objects| -------------------------------------------- | id | Collection_id | Object Type | --------------------------------------------| | 1 | 1 | Classification | | 2 | 1 | Space | | 3 | 2 | Classification | | 4 | 3 | Classification | | 5 | 3 | Space | --------------------------------------------| |Classification (or other self-constructing table)| ------------------------------------------------------------ | id | object_id | Some column | ,,, | ,,, | --------------------------------------------|--------------- | 1 | 1 | val | | 2 | 1 | val | | 3 | 2 | val | | 4 | 4 | val | | 5 | 4 | val | | 6 | 5 | val | --------------------------------------------| </code></pre> <p>Effectively cloning the entire object structure and it's children for a given node (node used as id)</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