Skip to content

Commit 843cf4a

Browse files
Merge pull request #1242 from mrrobot47/fix/boolean_value_saving
Fix saving and getting boolean value in db
2 parents 6fed28a + 4c70aa2 commit 843cf4a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

php/EE/Model/Base.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,18 @@ public static function create( $columns = [] ) {
166166
* Returns all model with condition
167167
*
168168
* @param string|array $column Column to search in
169-
* @param string $value Value to match
169+
* @param string $value Value to match
170170
*
171171
* @throws \Exception
172172
*
173173
* @return array
174174
*/
175175
public static function where( $column, $value = '' ) {
176+
177+
if ( is_bool( $value ) ) {
178+
$value = (int) $value;
179+
}
180+
176181
return static::many_array_to_model(
177182
EE::db()
178183
->table( static::$table )
@@ -245,8 +250,15 @@ public function __unset( $name ) {
245250
* @return bool Model saved successfully
246251
*/
247252
public function save() {
253+
248254
$fields = $this->fields;
249255

256+
foreach ( $fields as $key => $value ) {
257+
if ( is_bool( $value ) ) {
258+
$fields[ $key ] = (int) $value;
259+
}
260+
}
261+
250262
if ( static::$needs_update_timestamp ) {
251263
$fields = array_merge(
252264
$fields, [

0 commit comments

Comments
 (0)