Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's impossible to alter value of a PK #1004

Closed
LeonMelis opened this issue Oct 5, 2015 · 0 comments
Closed

It's impossible to alter value of a PK #1004

LeonMelis opened this issue Oct 5, 2015 · 0 comments

Comments

@LeonMelis
Copy link

Using the following schema as example:

Note that for the PK autoIncrement is not set.

When trying to change a primary key:

$item = ItemQuery::create()->findPK(1);
$item->setPrimaryKey(2);
$item->save();

Will result in a query:
UPDATE item SET id = 2 WHERE id = 2;

Assuming that ID 2 not exists for this example, the query would affect 0 rows.

in model->doUpdate() the buildPkeyCriteria() method is used to create the selectCriteria, it builds a selection criteria based on $this->id as the value, but $this->id is already set to the new value by setPrimaryKey(), resulting in a WHERE clause containing the new ID, where the old ID would be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant