Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do set NULL into the table in Doctrine

Tags:

php

doctrine

I have some table store_section(id,parent_id,label), I want to change some row, set parent_id=null.

I trying to:

$record = $table->getTable()->find( $id );
$record->parent_id = null;
$record->save();

But this isn't work. How can I do set NULL into the table in Doctrine, in example above, parent_id becomes =0 (not =NULL)?

Thnx for the responses!

like image 894
ajile Avatar asked Sep 17 '10 11:09

ajile


2 Answers

I would try one of the following:

1:

$record = $table->getTable()->find( $id );
$record->parent_id = new Doctrine_Null();
$record->save();

2:

$record = $table->getTable()->find( $id );
$record->parent_id = "NULL";
$record->save();

I have not tested these, but I do recall having a similar issue prior, just cannot recall how I solved it. Hope this helps!

like image 70
KSolo Avatar answered Oct 07 '22 12:10

KSolo


You can use method set('u.name', 'NULL') For example:

Doctrine_Query::create()->update('User u')->set('u.name', 'NULL')->where('u.id = ?',$id);
like image 37
Sergey Kharchishin Avatar answered Oct 07 '22 11:10

Sergey Kharchishin