[DC-489] Doctrine_Record seems to have a bug with default values when updating Created: 10/Feb/10  Updated: 20/Jan/11

Status: Open
Project: Doctrine 1
Component/s: Record
Affects Version/s: 1.2.1
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: Silver Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 1
Labels: None
Environment:

PHP 5.2.11



 Description   

So lets see the table:

User:
tableName: users
columns:
id:
type: integer(1)
fixed: false
unsigned: true
primary: true
autoincrement: true
username:
type: string(32)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
password:
type: string(48)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
role:
type: enum
fixed: false
unsigned: false
values:

  • admin
  • support
    default: support <----- Unable to render embedded object: File (ROOT OF EVIL) not found.
    primary: false
    notnull: true
    autoincrement: false

So lets say we have a user with `role` = 'support' and want to set em
'admin' we wrote

$user = new App_Model_User();
$user->assignIdentifier(1);
$user->role = 'admin';
$user->save();
var_dump($user->toArray());

in debugger we see SQL query been made:

  1. [0.55 ms] UPDATE users SET role = ? WHERE id = ?
  • bindings: admin
  • 1

array(6)

{ ["id"]=> int(1) ["display_name"]=> string(13) "Administrator" ["username"]=> string(4) "root" ["password"]=> string(40) "45bb0f589525a2f0f2a48620bb59b1b8baef0c1d" ["role"]=> string(5) "admin" ["is_active"]=> bool(true) }

Superb! Works as it should! So lets now set role of this user back to
'support':

$user = new App_Model_User();
$user->assignIdentifier(1);
$user->role = 'support'; // This value defined as default in scheme,
thats why have problems
$user->save();
var_dump($user->toArray());

in debugger we didnot see any UPDATE queries! However object is been
changed, results just has not been flushed to database.

array(6)

{ ["id"]=> int(1) ["display_name"]=> string(13) "Administrator" ["username"]=> string(4) "root" ["password"]=> string(40) "45bb0f589525a2f0f2a48620bb59b1b8baef0c1d" ["role"]=> string(7) "support" ["is_active"]=> bool(true) }

I cant overcome this problem right now, unfortunatelly (well I can
just remove all default values from table definitions or use
Doctrine_Query for updating staff.. but I'd like to use models

However if I use Doctrine_Query of even

$user = Doctrine_Core::getTable('App_Model_User')->find(1);

instead of

$user = new App_Model_User();
$user->assignIdentifier(1);

updates works well...



 Comments   
Comment by Petr Peller [ 20/Jan/11 ]

I second this.

When you UPDATE row with save() method of Record after setting identifier by assignIdentifier() doctrine removes columns updates from SQL which are set to default values same as it would do with INSERT. Other columns are updated correctly. This is sure a bug.

You can workaround this by setting the value as NULL instead of the actual default value. (Which I wouldn't recommend).

Generated at Wed Jul 30 17:13:58 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.