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

Problem with my deleted_by & deleted_at #212

Open
prashantnirgun opened this issue Oct 29, 2015 · 5 comments
Open

Problem with my deleted_by & deleted_at #212

prashantnirgun opened this issue Oct 29, 2015 · 5 comments

Comments

@prashantnirgun
Copy link

Hi friends I am new to base model deleted_by & deleted_at is not functioning properly null value is updated can anybody help whats wrong in my code.

class Article_model extends MY_Model{
//should i kept it before OR after ?
public $after_delete = array( 'delete_timestamps' );
protected $soft_delete = TRUE;
//my column name is deleted_by such case still i have to mentioned or its optional
protected $deleted_by_key = 'deleted_by';

protected function delete_timestamps($article)
{
$article['deleted_at'] = date('Y-m-d H:i:s');
return $article;
}
}

//Controller
class Test extends CI_Controller {
$this->load->model('article_model');
$this->article_model->delete(11);
}

//error reported
A PHP Error was encountered
Severity: Warning
Message: Cannot use a scalar value as an array
Filename: models/article_model.php
Line Number: 51

//table structure
CREATE TABLE articles (
body text,
title varchar(250) DEFAULT NULL,
id int(11) NOT NULL AUTO_INCREMENT,
created_at datetime NOT NULL,
last_updated datetime NOT NULL,
deleted_at datetime NOT NULL,
deleted tinyint(4) NOT NULL DEFAULT '0',
deleted_by int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
FULLTEXT KEY body (body,title)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1

@prashantnirgun
Copy link
Author

yeh I do agree with after_delete but then it is giving error
Message: Cannot use a scalar value as an array

@michail1982
Copy link

$this->_database->delete($this->_table); and $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); return scalar values instate of row_data

you can use $before_delete to add $this->_database->set('deleted_at',date('Y-m-d H:i:s'));

@prashantnirgun
Copy link
Author

Thanks Michail somehow the error message gone. Now still its not updating time stamp and deleted_by
I believe soft delete feature has in built functionality to handle this column. I can play around and managed to update the values in column. Since this is going to happened for every column than its very serious and has to find out whats going wrong?

Anybody can share tar the working code ?

@michail1982
Copy link

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