Welcome Guest, Not a member yet? Register   Sign In
Update using WHERE
#12

(This post was last modified: 01-20-2022, 01:30 PM by sevmusic.)

(01-20-2022, 08:38 AM)BilltheCat Wrote:
(01-20-2022, 08:02 AM)sevmusic Wrote: Yes. All fields are in $allowedFields.

Thanks for helping.

I really think Ci4 update() only wants to update with a primary key. Anything outside of that, it explodes.

(01-14-2022, 05:09 PM)kenjis Wrote: Did you set $allowedFields in your model?
https://codeigniter.com/user_guide/model...your-model
$allowedFields


There's an easy way to prove/disprove your theory....
PHP Code:
echo $this->where('activity_id'$activity_id)->getCompiledSelect(); 


It gave me this:

Quote:SELECT * FROM `billing_charges_2` WHERE `activity_id` = 8583

(01-20-2022, 11:53 AM)demyr Wrote: We had better clarify everything. 

So, in your controller : 


Code:
$activity_id = xyz-whatever;
$data = [
   'activity_id' => NULL
];

$this->YourModel->lets_update_it($data, $activity_id);

Your model : 


Code:
public function lets_update_id($data, $activity_id){
$db      = \Config\Database::connect();
$builder = $db->table('your_table_name');
$query = $builder->where('activity_id', $activity_id)
->update($data);
}

That should work.


YOU NAILED IT!

This query builder has been the most confusing part of Ci4. All my model functions (except for this one) works as expected.

I don't care why at this point.

THANK YOU!!!!!
Reply


Messages In This Thread
Update using WHERE - by sevmusic - 01-11-2022, 01:37 PM
RE: Update using WHERE - by BilltheCat - 01-11-2022, 01:43 PM
RE: Update using WHERE - by sevmusic - 01-11-2022, 02:13 PM
RE: Update using WHERE - by iRedds - 01-11-2022, 02:47 PM
RE: Update using WHERE - by sevmusic - 01-11-2022, 03:47 PM
RE: Update using WHERE - by BilltheCat - 01-11-2022, 08:06 PM
RE: Update using WHERE - by sevmusic - 01-14-2022, 07:52 AM
RE: Update using WHERE - by kenjis - 01-14-2022, 05:09 PM
RE: Update using WHERE - by sevmusic - 01-20-2022, 08:02 AM
RE: Update using WHERE - by BilltheCat - 01-20-2022, 08:38 AM
RE: Update using WHERE - by sevmusic - 01-20-2022, 01:20 PM
RE: Update using WHERE - by demyr - 01-20-2022, 11:53 AM
RE: Update using WHERE - by demyr - 01-20-2022, 02:10 PM
RE: Update using WHERE - by kenjis - 01-20-2022, 06:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB