Open Aneta1990 opened 8 years ago
I can't save any object.
Help please
@Aneta1990 You have to provide some details on your issue. Do you get any error messages? What exactly are you trying to save?
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.
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;
}
}`
READ WORK
SAVE NOT WORKING!!!!!!!!!!