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

updating primary key Value failed #210

Open
Sysix opened this issue Dec 10, 2016 · 2 comments
Open

updating primary key Value failed #210

Sysix opened this issue Dec 10, 2016 · 2 comments

Comments

@Sysix
Copy link

Sysix commented Dec 10, 2016

Hey guys,

I think I have found a bug.
When I update a Entity's primary key, it would be no changes at all.
My fields are:

    public static function fields()
    {
        return [
            'scope' => [
                'type' => 'string',
                'primary' => true
            ],
            'is_default' => [
                'type' => 'boolean',
                'default' => 0
            ]
        ];
    }

My Update code is:

            /** @var \Spot\EntityInterface $entity */
            $entity->data(array(
'scope' => $newScope
));

            $scopes->getMapper()->update($entity);

Xdebug Outputs on Doctrine\DBAL\Connection on line 665:

$sql = "UPDATE `oauth_scopes` SET `scope` = ? WHERE `scope` = ?"
$params = array('newValue', 'newValue'); 

But it should be:

$params = array('newValue', 'oldValue'); 
@tuupola
Copy link
Contributor

tuupola commented Jan 27, 2017

Primary keys should not contain business logic. Better to use unsigned integer as primary key. You can still have scope as unique.

@Sysix
Copy link
Author

Sysix commented Jan 27, 2017

Hello,

yes I know its the "better" art of building a Database. But this way should be valid too. With "Vanilla-SQL" it works. So I think is should work with spot2 too.

I added a unsigned primary key id and now it works. But this problem is still active for the framework.

@vlucas vlucas closed this as completed Feb 24, 2017
@vlucas vlucas reopened this Feb 24, 2017
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

3 participants