Skip to content

Commit 8c78328

Browse files
committed
Adjusting the soft delete conditions code - no need for multiple booleans
1 parent 96fd20a commit 8c78328

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

core/MY_Model.php

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ public function get($primary_value)
136136

137137
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
138138
{
139-
$this->_database->where($this->soft_delete_key, FALSE);
140-
}
141-
142-
if ($this->soft_delete && $this->_temporary_only_deleted)
143-
{
144-
$this->_database->where($this->soft_delete_key, TRUE);
139+
$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
145140
}
146141

147142
$row = $this->_database->where($this->primary_key, $primary_value)
@@ -166,12 +161,7 @@ public function get_by()
166161

167162
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
168163
{
169-
$this->_database->where($this->soft_delete_key, FALSE);
170-
}
171-
172-
if ($this->soft_delete && $this->_temporary_only_deleted)
173-
{
174-
$this->_database->where($this->soft_delete_key, TRUE);
164+
$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
175165
}
176166

177167
$this->trigger('before_get');
@@ -193,12 +183,7 @@ public function get_many($values)
193183
{
194184
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
195185
{
196-
$this->_database->where($this->soft_delete_key, FALSE);
197-
}
198-
199-
if ($this->soft_delete && $this->_temporary_only_deleted)
200-
{
201-
$this->_database->where($this->soft_delete_key, TRUE);
186+
$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
202187
}
203188

204189
$this->_database->where_in($this->primary_key, $values);
@@ -216,12 +201,7 @@ public function get_many_by()
216201

217202
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
218203
{
219-
$this->_database->where($this->soft_delete_key, FALSE);
220-
}
221-
222-
if ($this->soft_delete && $this->_temporary_only_deleted)
223-
{
224-
$this->_database->where($this->soft_delete_key, TRUE);
204+
$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
225205
}
226206

227207
return $this->get_all();
@@ -234,17 +214,12 @@ public function get_many_by()
234214
public function get_all()
235215
{
236216
$this->trigger('before_get');
237-
217+
238218
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
239219
{
240-
$this->_database->where($this->soft_delete_key, FALSE);
220+
$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
241221
}
242222

243-
if ($this->soft_delete && $this->_temporary_only_deleted)
244-
{
245-
$this->_database->where($this->soft_delete_key, TRUE);
246-
}
247-
248223
$result = $this->_database->get($this->_table)
249224
->{$this->_return_type(1)}();
250225
$this->_temporary_return_type = $this->return_type;

0 commit comments

Comments
 (0)