Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Model update() only set first array value #3764

Closed
andresyebenes opened this issue Oct 13, 2020 · 2 comments
Closed

Bug: Model update() only set first array value #3764

andresyebenes opened this issue Oct 13, 2020 · 2 comments

Comments

@andresyebenes
Copy link

Describe the bug
When updating a Model with more than 1 array values, it only updates the first value (for first column) in the database.

CodeIgniter 4 version
CodeIgniter 4.0.4

Affected module(s)
CodeIgniter\Model

Expected behavior, and steps to reproduce if appropriate
Code used from the Controller:

$db = \Config\Database::connect();
$data = [
    'is_allowed' => 1,
    'is_dismissed' => 0
];
$questionsModel = new \App\Models\QuestionsModel();
$questionsModel->update(intval($id), $data);

d($data);
d($db->getLastQuery()->getQuery());

And:

$db = \Config\Database::connect();
$questionsModel = new \App\Models\QuestionsModel();
$questionsModel->where('id', $id)
        ->set($data)
        ->update();

d($data);
d($db->getLastQuery()->getQuery());

Both methods for updating mutiple columns are printing this query;
UPDATE questions SET is_allowed = 1, updated_at = '2020-10-13 12:17:50' WHERE questions.id IN (1)

And:

UPDATE questions SET is_allowed = 1, updated_at = '2020-10-13 12:17:50' WHERE id = '1'

Expected query should be:
UPDATE questions SET is_allowed = 1, is_dismissed = 0, updated_at = '2020-10-13 12:17:50' WHERE id = '1'

Context

  • OS: Linux
  • Web server Apache 2
  • PHP version: PHP 7.4.6
@andresyebenes andresyebenes added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 13, 2020
@michalsn
Copy link
Member

Are you sure you added is_dismissed to the Model's $allowedFields array?

@andresyebenes
Copy link
Author

Well, you're right, I didn't add it to $allowedFields.

Thank you!

@paulbalandan paulbalandan removed the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants