When I am saving data having two enum fields to manage to manage status of message i.e. read or unread by user. I am using enum ('1','0') to manage status '1' => read and '0'=> unread
following code will save the message but in status column saving empty filed
$data = array(
'message' => 'test message',
'status' => 1
);
$this->Message->save($data);
database structure is as follow
Field Type Collation Null Key Default
------------------ ------------- ----------------- ------ ------ -------
id bigint(20) (NULL) NO PRI (NULL)
message varchar(255) (NULL) NO MUL (NULL)
status enum('0','1') latin1_swedish_ci NO MUL 0
even I have used data array as
$data = array(
'message' => 'test message',
'status' => '1'
);
$data = array(
'message' => 'test message',
'status' => "'".1."'"
);
you are using cakephp - it does (as documented) not support ENUM. and in your case it is wrong to even use enums in the first place. Enums are used for more than two states and should be emulated as ArrayDatasource or in your model (as I do).
But "read/unread" is a boolean (two definite states!).
and there is an easy way to accomplish this correctly:
tinyint(1) [unsigned] [default 0]
cake will automatically assume this is a boolean and will transform the form field for it into a checkbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With