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

From_form update affects all records #291

Open
Wouter60 opened this issue Sep 2, 2019 · 4 comments
Open

From_form update affects all records #291

Wouter60 opened this issue Sep 2, 2019 · 4 comments

Comments

@Wouter60
Copy link

Wouter60 commented Sep 2, 2019

I've setup a model based on MY_Model to insert and update records from form. Inserting a new record works fine, but when I want to update a record, all field values from the form are written to all records in the table. I went throught the model code, the controller and the view several times, but I can't find where I'm doing something wrong. Can you help me fix this?

@avenirer
Copy link
Owner

avenirer commented Sep 3, 2019

Did you pass the id of the row? The primary key...

@Wouter60
Copy link
Author

Wouter60 commented Sep 3, 2019

Yes, I did.
In the controller I have:

$updated = $this->gemeenten_model->from_form(NULL,NULL,array('id'=>$id))->update();

$id is passed to the controller function as the third segment.
I've checked if $id has a value. That's always the case.,

In my 'gemeenten_model':

public $table = 'gemeenten;
public $primary_key = 'id';
public $fillable = array('plaats','gemeente_naam');

I checked the query that is generated by the model, with $this->db->last_query(). The outcome of that is:
UPDATE gemeenten SET gemeente_naam = 'Testgemeente', plaats = 'Testplaats', updated_at = '2019-09-03 15:34:27'

So no sign of the primary key here.

@venonw
Copy link

venonw commented Oct 26, 2019

change below line:
$updated = $this->gemeenten_model->from_form(NULL,array('id'=>$id),array('id'=>$id))->update();

@Wouter60
Copy link
Author

change below line: $updated = $this->gemeenten_model->from_form(NULL,array('id'=>$id),array('id'=>$id))->update();

No, this doesn't work either. Creating a record with the from_form method works flawlessly, but if I update one record, all records in the table are affected, i.e. they become identical to the one that I wanted to update.

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