-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
where NULL is causing problems #295
Comments
Here you can write your where like this
Result for a select query: |
I know it, you did not understood me. |
Then you should validate $some_value to make sure it is not NULL. |
as I said I just expecting MY_Model behave same as QB in this case. |
@nuryagdym class Base_Model extends MY_Model {
public function __construct()
{
parent::__construct();
}
public function whereNull($key)
{
$this->where($key . ' IS NULL', NULL, FALSE,FALSE,FALSE,TRUE);
return $this;
}
public function whereNotNull($key)
{
$this->where($key . ' IS NOT NULL', NULL, FALSE,FALSE,FALSE,TRUE);
return $this;
}
}
// $this->Products_model->whereNull('user_id')->get_all(); |
When I say,
$this->where('user_id', $some_value) ->update($update_data);
it is not problem until we $some_value is NULL.
if $some_value is NULL normally if we don't use MY_Model it is not problem
BUT on MY_Model when $some_value = NULL then query becomes:
update mytable set update_field=value
I mean
where user_id IS NULL
is not added which updates all the rows in table
I faced this problem several times, in accidently updated all rows, because without using MY_Model I don't have to control if $some_value is null in PHP, QB will generate
WHERE user_id IS NULL
thus, nothing will be updated.The text was updated successfully, but these errors were encountered: