Welcome Guest, Not a member yet? Register   Sign In
suggest to change the position of the parameters of the update in class Model
#1

(This post was last modified: 05-28-2020, 02:35 AM by afraid.jpg.)

I think, when i use update(), I always need to set the data, but not use the primary key every time. So suggest to change the position of the parameters from 

public function update($id = null, $data = null)
to
public function update($data = null, $id = null)
Reply
#2

Hi, as this are a breaking change, it won't happen until version 5 as the soonest.

What kind of data are you putting in $data without and $id specified?
Reply
#3

(05-28-2020, 10:55 AM)jreklund Wrote: Hi, as this are a breaking change, it won't happen until version 5 as the soonest.

What kind of data are you putting in $data without and $id specified?
Sorry for so long time to reply.

For example, in my case, I need to interface the third-part api, they have an unique id like "uuid", in my table, I defined id and uuid in the same table, then some sometimes they have some callback event or event push to my server with uuid. So I need to update my data like this:


$uuid = $this->request->getPost('uuid');
$data = .... ;
$room_model = new RoomModel();
$room_model->where('uuid', $uuid)->update(null, $data);

The important things is, not all record's uuid field has value, so I can't use uuid to be the primary key
Reply
#4

(This post was last modified: 06-18-2020, 08:40 AM by jreklund.)

If you are doing all that, it would be better to just make a function in your RoomModel.

PHP Code:
function updateByUUID(string $uuid$data)
{
    return 
$this->->where('uuid'$uuid)->update(null$data);
}

// ...

$uuid $this->request->getPost('uuid');
// ...
$room_model = new RoomModel();
$room_model->updateByUUID($uuid$data); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB