CodeIgniter Forums
Deletes are not allowed unless they contain a "where" or "like" clause. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: Deletes are not allowed unless they contain a "where" or "like" clause. (/thread-75760.html)



Deletes are not allowed unless they contain a "where" or "like" clause. - pippuccio76 - 03-13-2020

HI , this is my code :


Code:
        $this->db->from('eventi_partecipanti_accompagnatori');
        $this->db->join('accompagnatori_club', 'accompagnatori_club.id=eventi_partecipanti_accompagnatori.id_accompagnatori_club', 'left');
        $this->db->join('user', 'accompagnatori_club.id_user=user.id', 'left');
        $this->db->where('eventi_partecipanti_accompagnatori.id_eventi', $id_eventi);
        $this->db->where('user.id', $id_user);
       
        if($this->db->delete('eventi_partecipanti_accompagnatori')){

            return TRUE;

        }else{

            return FALSE;

        }


But i have this error :

Code:
Deletes are not allowed unless they contain a "where" or "like" clause.


How can i solve it ?


RE: Deletes are not allowed unless they contain a "where" or "like" clause. - neuron - 03-13-2020

I see it is hard coded in the system QB, you can either implement your custom QB and override delete method or implement your own method, 
or you can add dummy where $this->db->where('1=1', NULL, FALSE);
Do little research on how to extend query builder, there are must be examples. Because it is also requires to extend the Loader library

This rule is implemented for safety reason, you may unintentionally delete all the records in the table which may cause more headache for you.


RE: Deletes are not allowed unless they contain a "where" or "like" clause. - pippuccio76 - 03-13-2020

(03-13-2020, 06:09 AM)neuron Wrote: I see it is hard coded in the system QB, you can either implement your custom QB and override delete method or implement your own method, 
or you can add dummy where $this->db->where('1=1', NULL, FALSE);
Do little research on how to extend query builder, there are must be examples. Because it is also requires to extend the Loader library

This rule is implemented for safety reason, you may unintentionally delete all the records in the table which may cause more headache for you.
But there are two where , join but there are...


RE: Deletes are not allowed unless they contain a "where" or "like" clause. - neuron - 03-13-2020

I am sorry Smile, I don't why I did not have look to your code, before answering.

I never did delete with using QB, so I am not sure your code produces the right SQL code. 
try running

Code:
echo $this->db->get_compiled_delete('eventi_partecipanti_accompagnatori');
and check the SQL code it generates

(03-13-2020, 06:53 AM)neuron Wrote: I am sorry Smile, I don't why I did not have look to your code, before answering.

I never did delete with using QB, so I am not sure your code produces the right SQL code. 
try running

Code:
echo $this->db->get_compiled_delete('eventi_partecipanti_accompagnatori');
and check the SQL code it generates

Also I see you can remove 'left' arguments from you joins, as where clause will eventually filter those NULL fields.


RE: Deletes are not allowed unless they contain a "where" or "like" clause. - pippuccio76 - 03-13-2020

(03-13-2020, 06:53 AM)neuron Wrote: I am sorry Smile, I don't why I did not have look to your code, before answering.

I never did delete with using QB, so I am not sure your code produces the right SQL code. 
try running

Code:
echo $this->db->get_compiled_delete('eventi_partecipanti_accompagnatori');
and check the SQL code it generates

(03-13-2020, 06:53 AM)neuron Wrote: I am sorry Smile, I don't why I did not have look to your code, before answering.

I never did delete with using QB, so I am not sure your code produces the right SQL code. 
try running

Code:
echo $this->db->get_compiled_delete('eventi_partecipanti_accompagnatori');
and check the SQL code it generates

Also I see you can remove 'left' arguments from you joins, as where clause will eventually filter those NULL fields.


I insert the query without QB and the query it'ok run on adminer ( similar to phpmyadmin)

Code:
$sql = "DELETE eventi_partecipanti_accompagnatori
                from eventi_partecipanti_accompagnatori
                join accompagnatori_club on accompagnatori_club.id=eventi_partecipanti_accompagnatori.id_accompagnatori_club
                JOIN user on accompagnatori_club.id_user=user.id
                WHERE user.id= $id_user
                AND eventi_partecipanti_accompagnatori.id_eventi = $id_eventi";
        $res=$this->db->query($sql);
       
        if($res){

            return TRUE;

        }else{

            return FALSE;

        }


but same problems...


RE: Deletes are not allowed unless they contain a "where" or "like" clause. - pippuccio76 - 03-18-2020

(03-13-2020, 10:14 AM)pippuccio76 Wrote:
(03-13-2020, 06:53 AM)neuron Wrote: I am sorry Smile, I don't why I did not have look to your code, before answering.

I never did delete with using QB, so I am not sure your code produces the right SQL code. 
try running

Code:
echo $this->db->get_compiled_delete('eventi_partecipanti_accompagnatori');
and check the SQL code it generates

(03-13-2020, 06:53 AM)neuron Wrote: I am sorry Smile, I don't why I did not have look to your code, before answering.

I never did delete with using QB, so I am not sure your code produces the right SQL code. 
try running

Code:
echo $this->db->get_compiled_delete('eventi_partecipanti_accompagnatori');
and check the SQL code it generates

Also I see you can remove 'left' arguments from you joins, as where clause will eventually filter those NULL fields.


I insert the query without QB and the query it'ok run on adminer ( similar to phpmyadmin)

Code:
$sql = "DELETE eventi_partecipanti_accompagnatori
                from eventi_partecipanti_accompagnatori
                join accompagnatori_club on accompagnatori_club.id=eventi_partecipanti_accompagnatori.id_accompagnatori_club
                JOIN user on accompagnatori_club.id_user=user.id
                WHERE user.id= $id_user
                AND eventi_partecipanti_accompagnatori.id_eventi = $id_eventi";
        $res=$this->db->query($sql);
       
        if($res){

            return TRUE;

        }else{

            return FALSE;

        }


but same problems...

Sorry the file isn't uploaded  , the query work fine.