Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how to update column on where condition?

the method of save and update didn't like the find and findFirst which receive the condition parameter...

Please give more information.



4.9k
edited Apr '14

example code:

$address = new Address();
$address->id = $id;
$address->userId = $userId;
$address->update($_POST);

i want the sql executed is UPDATE address SET xx=xx WHERE id=$id AND userId=$userId, but actually executed is UPDATE address SET xx=xx, userId=$userId WHERE id=$id... and i don't know how to pass the where condition to the update or save method...



50.0k
Accepted
answer

The "where" condition is automatically determined by Phalcon, based on the primary key of the Address table. If you want userID to be included in the WHERE clause, you need to make it part of the primary key.

If you don't/cant do that, you'll have to resort to PHQL and building the query yourself.



4.9k
edited Apr '14

oh, i see... thank you very much!

edited Apr '14

Hello, It seems that this question is similar to mine, so I will post it here. I have this function that doesn't work. It doesn't return any error, but it doesn't updates the record in database. Is there something wrong with phalcon update? I've tried also with other functions and it didn't work either.

public static function updateResponse($response,$sugester,$sugested,$location_id) {

$sql = "UPDATE Sugestion SET response=$response WHERE sugester=$sugester AND sugested=$sugested AND locationid=$locationid;";

$sugestion = new Sugestion();

return new Resultset(null, $sugestion, $sugestion->getReadConnection()->query($sql));

}

It's just making an update in a record. What ever I do, it just doesn't update. Thank you so much!

@pusoiuandrei

This question has been answered - if you're having a problem of your own, please start a new thread.