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() function always return true #31

Open
pujexx opened this issue Jan 29, 2017 · 1 comment
Open

save() function always return true #31

pujexx opened this issue Jan 29, 2017 · 1 comment

Comments

@pujexx
Copy link

pujexx commented Jan 29, 2017

hello,
save function always return true
var_dump($model->save());
you can fix it ?

@pajtai
Copy link

pajtai commented May 3, 2018

@pujexx This is how I solved this issue:

<?php

use WeDevs\ORM\Eloquent\Model;

/**
 * Class ClassBaseModel
 *
 * We need a Base Model, since by default model saves can trigger errors
 * without throwing anything.
 */
class ClassBaseModel extends Model {

	public function save(array $options = []) {
		$saved = parent::save($options);
		$error = $this->getConnection()->db->last_error;
		if ($error) {
			throw new \Exception($error);
		}
		return $saved;
	}
}

Then you always create a new Model Class by extending the above.

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

2 participants