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

SAVE NOT WORKING #12

Open
Aneta1990 opened this issue Feb 14, 2016 · 5 comments
Open

SAVE NOT WORKING #12

Aneta1990 opened this issue Feb 14, 2016 · 5 comments

Comments

@Aneta1990
Copy link

READ WORK

SAVE NOT WORKING!!!!!!!!!!

@Aneta1990
Copy link
Author

I can't save any object.

@Aneta1990
Copy link
Author

Help please

@perssonmattias91
Copy link

@Aneta1990 You have to provide some details on your issue. Do you get any error messages? What exactly are you trying to save?

@al-v-in
Copy link

al-v-in commented Nov 6, 2017

Same issue. Reading via models works fine. Insert via DB facade works fine. But save via models doesnt work though returns true and gives no exceptions.

@eclipsesrl
Copy link

Guys think I've found the issue, it's a mismatch between ID and id of the model, practically even if you have set the primarykey and the guarded to ID, the model returns id in lower case, so before saving updating or deleting you have to set the property ID to the one saved in id

`use WeDevs\ORM\Eloquent\Model;

class ClassBaseModel extends Model
{

public function save(array $options = []) {
    if ($this->id) {
        $this->ID = $this->id;
    }
    $saved = parent::save($options);
    $error = $this->getConnection()->db->last_error;

    if ($error) {
        throw new \Exception($error);
    }
    return $saved;
}

public function delete()
{
    if ($this->id) {
        $this->ID = $this->id;
    }
    $deleted = parent::delete();
    $error = $this->getConnection()->db->last_error;

    if ($error) {
        throw new \Exception($error);
    }
    return $deleted;
}

public function update(array $attributes = [], array $options = [])
{
    if ($this->id) {
        $this->ID = $this->id;
    }
    $updated = parent::update($attributes, $options);
    $error = $this->getConnection()->db->last_error;

    if ($error) {
        throw new \Exception($error);
    }
    return $updated;

}

}`

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

4 participants