-
Notifications
You must be signed in to change notification settings - Fork 58
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
Would "update" inserts empty values? #25
Comments
There's no distinction between empty values and non-empty values. If you update a row with empty values, that will be saved in the database. $user = $db->user->select()
->one()
->byId($_POST['data']['id'])
->run();
if ($user) {
$data = array_filter($_POST['data']); //discard empty values
$user->edit($data); //edit the existing user
} else {
$user = $db->user->create($_POST['data']); //create the user
}
$user->save(); //save data |
Great! what's the difference between Man each time I ask you a question; you show something new about this library, I wish I have the time to go through it line by line and write a complete documentation. |
foreach ($data as $field => $value) {
$user->$field = $value;
}
|
if data is related to another field, you edit, should you do
or is And one more thing I keep getting
Query not found, strange |
If the data is already related, you don't need to relate it again. About the exception, you're executing //You can do this:
$user = $db->user[4];
$user->edit($newData);
$user->save();
//Or this
$db->update()
->data($newData)
->byId(4)
->run(); |
Just want to ask a small question, no need to create new issue. Is there a function that would throw an error if something goes wrong during the CRUD? or is something like this enough?
The reason is I have to notify the user in case his data wasn't inserted, deleted whatever. |
If something is wrong, an exception is throw. Isn't it enought? |
Ok then I'll do it in a try catch. Thank you |
I can use normal pdo exceptions? for instance to check if someone is trying to duplicates in unique field that would be
And where does |
Why don't you check this before asking?
That is just an example of a hypothetical |
To insert I do
$user = $db->user->create($_POST['data']);
Would that work for update too? I mean if there's an empty values in the form, would it override the existent values or would it ignore the empty values and insert what's not empty? How to update none empty values by doing the same thing as insert?
The text was updated successfully, but these errors were encountered: