Model basic CRUD methods and other queries on other tables using $this->db->table() |
I'm having what looks to me like a bug.
I have a model configured like this: PHP Code: protected $table = 'sottoeventi'; Here are a number of methods that use CRUDs to execute various queries on the table set in $table. but in certain situations I need to run queries on other tables before or after, so, in the specific case I have this kind of situation: PHP Code: // More code By doing so, however, I receive an error from the second query, that of update on the model table ($table) There is no data to update. If I modify the query using the table() function like this: PHP Code: $this->db->table('sottoeventi')->where('id', (int)$id_sottoevento) everything works I tried printing the $this->table variable, before and after the first query, but the value is correct. At this point, I would expect the query to work normally when I update like this: PHP Code: $this->where('id', (int)$id_sottoevento) Didn't I understand? or is there something wrong? Quote:To help protect against Mass Assignment Attacks, the Model class requires that you list all of the field names that can be changed during inserts and updates in the $allowedFields class property.
(02-21-2023, 10:22 PM)kenjis Wrote:Quote:To help protect against Mass Assignment Attacks, the Model class requires that you list all of the field names that can be changed during inserts and updates in the $allowedFields class property. Another question, in the documentation in the "Upgrading From a Previous Version" section, there is no mention of version 4.3.2 which however is available from composer, is it just an oversight? (02-21-2023, 10:22 PM)kenjis Wrote:Quote:To help protect against Mass Assignment Attacks, the Model class requires that you list all of the field names that can be changed during inserts and updates in the $allowedFields class property. I fixed it, I thought I understood the problem, i.e. that the "start_date" and "end_date" fields weren't present in the $allowedFields array, but even adding them, I still have problems, what didn't I understand? (02-22-2023, 02:15 AM)serialkiller Wrote: Another question, in the documentation in the "Upgrading From a Previous Version" section, there is no mention of version 4.3.2 which however is available from composer, is it just an oversight? See https://codeigniter4.github.io/CodeIgnit...e_432.html (02-22-2023, 02:15 AM)serialkiller Wrote: I fixed it, I thought I understood the problem, i.e. that the "start_date" and "end_date" fields weren't present in the $allowedFields array, but even adding them, I still have problems, what didn't I understand? What are "start_date" and "end_date"? Your fields are "data_inizio" and "data_fine".
(02-22-2023, 02:47 AM)kenjis Wrote:So I don't understand why it isn't marked here(02-22-2023, 02:15 AM)serialkiller Wrote: Another question, in the documentation in the "Upgrading From a Previous Version" section, there is no mention of version 4.3.2 which however is available from composer, is it just an oversight? https://codeigniter.com/user_guide/insta...ading.html For the problem of the post, what am I still doing wrong?
(02-22-2023, 02:55 AM)kenjis Wrote: See the Note in https://forum.codeigniter.com/showthread...#pid406955 ok, thanks, I didn't read. Back to the main problem, earlier I mistakenly forgot to add the 2 fields in the "allowedFields" list, now they are present, but it keeps telling me "There is no data to update", if I use the table('table_name') function, it works
When you use table('table_name'), you are using a new Query Builder instance directly.
You are not using the Model.
(02-22-2023, 03:06 AM)kenjis Wrote: When you use table('table_name'), you are using a new Query Builder instance directly. Yes, I know this, this is the problem right here, because if I don't use table() of the query builder, the query fails? The Model has its own table set, and the query in question should use that table "sottoeventi". Code: protected $table = 'sottoeventi'; In the specific case I first run other queries with the query builder, use different tables than the model one, then use table('other_table'). PHP Code: $this->db->table('sottoeventi_personale')->where('id_sottoevento', (int)$id_sottoevento)->delete(); The update query returns the error "There is no data to update", while you expect it to update the "sottoeventi" table, which is the Model |
Welcome Guest, Not a member yet? Register Sign In |