Note that there are some explanatory texts on larger screens.

plurals
  1. POcf ORM - access generated property immediately after entitySave() on new entity
    primarykey
    data
    text
    <p>I am creating a new Entity, saving it with entitySave(), then want to get the ID for that entity before the page request finishes.</p> <p>When I run the getter on the ID, it returns '0', but when I check, the database has generated the ID.</p> <p>Here is my property declaration in my model:</p> <pre><code>property name="id" fieldtype="id" generator="identity" column="member_id"; </code></pre> <p>I create and save the entity, then try to access the new Entities ID:</p> <pre><code>newProfile = entityNew("member"); newProfile.setMemento(args); // a helper method to populate the entity entitySave(newProfile); //ormFlush() // have tried this, but makes no difference //ormReload(newProfile) // have tried this, but no difference //I now want to access the ID of the new profile, but it is returning '0' newProfileID = newProfile.getID(); </code></pre> <p>Have also tried this without success</p> <pre><code>transaction { entitySave(newProfile); } writeDump(newProfile); </code></pre> <p>Any pointers on what I might be missing here?</p> <p>Many Thanks!</p> <p><em><strong></em>**UPDATE*<em>*</em></strong> It looks like an issue with the colomn mapping. If I change the property name to be anything other than "id", it works fine. It is only if the property name is "id" that the property doesn't pick up the generated value:</p> <p>This configuration has getID() with a value of 0:</p> <pre><code>property name="id" fieldtype="id" generator="identity" column="member_id"; </code></pre> <p>Changing property name to something other than 'id' returns the value of member_id in the DB.</p> <pre><code>property name="myid" fieldtype="id" generator="identity" column="member_id"; </code></pre>
    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