Propel2
Propel2 copied to clipboard
update() does not convert enum value
I'm using propel2 in the current dev-master version and in my schema.xml I use an enum type like this:
<table name="my_table" idMethod="native" phpName="MyTable">
...
<column name="status" required="true" type="ENUM" valueSet="status1, status2, status3" default="status1" />
...
Then I want to do a bulk update of this table using the following code:
MyTableQuery::create()
->filterByStatus(array(
MyTableTableMap::COL_STATUS_STATUS1,
MyTableTableMap::COL_STATUS_STATUS2
))
->update(array(
'Status' => MyTableTableMap::COL_STATUS_STATUS3
));
But this will result in an SQL error like this:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'status3' for column 'status' at row 1
This is because the update() function does not convert the enum value as it does for the filterByStatus() function.
Instead I have to do something like this to get the internal integer value of the enum value and then use this for the update:
$valueSet = MyTableTableMap::getValueSet(MyTableTableMap::COL_STATUS);
$status3Int = array_search(MyTableTableMap::COL_STATUS_STATUS3, $valueSet);
...
->update(array(
'Status' => $status3Int
));
Please let me know if this is an issue in propel or if this is really the way I have to do it.
+1
I'm not sure if this is really a bug or just a limitation in the current enum implementation. I'd rather want to wait for the merge of #786. With this PR you can pass a string as column value as you wanted to use.
Is this still relevant or can it be closed?
@dereuromark : Do be honest, I totally forgot about this ticket and even didn't know anymore that I created it 😉 It was 5 years ago. Since I'm not using Propel2 not since a long time, I would suggest that you guys from the Propel2 community/development decide if this is still an issue and if it's something you want to change or not.