CodeIgniter Forums
restrict query in callback - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: restrict query in callback (/showthread.php?tid=88462)



restrict query in callback - sjender - 09-12-2023

Hi,

I want to do some checks prior to some queries in the model.
In the $beforeUpdate and $beforeDelete callback I append the query by 
PHP Code:
$this->builder()->where('id'null); 
when the conditions are not met. (my ID's won't ever be NULL, resulting in an UPDATE or DELETE which won't work)

But this won't work on an insert.

I have a callback which determines whether the insert is valid, but I can't find a way to prevent the insert from happening when the right conditions are not met.
I have tried $this->builder()->resetQuery, but that still doesn't prevent the query from running...


RE: restrict query in callback - sammyskills - 09-12-2023

You can try Conditional Statements.


RE: restrict query in callback - sjender - 09-12-2023

I've looked into that....

But how would I fit that into a callback function in the Model?
I don't want to use the WHEN method on every insert query, I would like to centralize it in the model


RE: restrict query in callback - kenjis - 09-12-2023

Why don't you throw an exception when the conditions are not met?