Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[1.6.3] A deep copy of a table which is "under version control" fail #20

Open
j0k3r opened this Issue · 0 comments

1 participant

@j0k3r

Hi,

Following the first part of this short discussion, we have a problem with the behavior versionable.

If you have a table which is versionable:

propel:
  user:
    id:             ~
    name:           { type: VARCHAR, size: '255', required: true }
  post:
    _propel_behaviors:
      versionable:  { log_created_at: true, log_created_by: true, log_comment: true }
    id:             ~
    ref:            { type: VARCHAR, size: '255', required: true }
    user_id:        { type: INTEGER, required: true, foreignTable: user, foreignReference: id, onDelete: cascade }

And tried to make a deepCopy of this table (post):

<?php
    $post= PostQuery::create()->findOneById(1);
    $newPost = $post->copy(true);
    $newPost->save();

Then you will have a SQL Error:

Unable to execute INSERT statement [INSERT INTO `post_version` (`ID`,`REF`,`VERSION`,`VERSION_CREATED_AT`) VALUES (:p1,:p2,:p3,:p4)] [wrapped: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-1' for key 'PRIMARY']

In fact, when you check the mysql queries, you see that the deepCopy also copy the post_version table.
And after the postSave of Post, it will try to addVersion for the new post (with version number 1). Here it fail.

The problem is in copyInto:

<?php
public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{
  // ....
  if ($deepCopy) {
    // ....
    foreach ($this->getPostVersions() as $relObj) {
      if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
        $copyObj->addPostVersion($relObj->copy($deepCopy));
      }
}

I think when we copy an object we don't need to retrieve all the past version and that's the same for the refers.

@apinstein apinstein referenced this issue from a commit in apinstein/Propel
@apinstein apinstein [gh-20] Add a "normalize" command to normalize the structure of the s…
…chema.xml file.

This optional feature helps minimize the changes to the schema XML file
(and thus the generated models) due to non-deterministic xml created via
external tools like "reverse" or the ERD->XML tools.
d4d4c60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.