Welcome Guest, Not a member yet? Register   Sign In
Using Jamie Rumbelow's MY Model
#1

[eluser]xtremer360[/eluser]
I'm using jamie Rumbelow's MY model as a way to better deal with my application.

The MY_model is the same except I have an added in variable for defining whether or not an item in the db is marked as being soft deleted or not.

Code:
protected $soft_delete_value = 3;

I only have that variable defined and have not altered his code yet to account for this value.

I have two things I want to do with this titles model that I need help understanding.

Titles Table - title_id, title_name, title_status_id
Title_Statuses_Table - title_status_id, title_status_name

What I want it to do is retrieve all of the rows that have a title_status_id of 1 and 2 and 3 because the soft delete value is different than the default set in the MY Model. What I would also like to have is instead of it returning the integer have it return the name of the status.

Expected results: An array of objects that contain a title_id, title_name, title_status_name for which the titles have a status id of 1,2, or 3.

Code:
$titles = $this->titles_model->get_all();
  echo "<pre>";
  print_r($titles);
  echo "</pre>";

Actual results:

Code:
SELECT *
FROM (`titles`)
WHERE `title_status_id` =  0
<pre>Array
(
)

Code:
class Titles_model extends MY_Model
{
/* --------------------------------------------------------------
    * VARIABLES
    * ------------------------------------------------------------ */

/**
    * This model's default database table.
    */
public $_table = 'titles';

public $primary_key = 'title_id';

/**
    * Support for soft deletes and this model's 'deleted' key
    */
public $soft_delete = TRUE;
public $soft_delete_key = 'title_status_id';
public $soft_delete_value = 4;
public $_temporary_with_deleted = FALSE;

    public function __construct()
    {
        parent::__construct();
    }
}
#2

[eluser]xtremer360[/eluser]
Any ideas?
#3

[eluser]qcsites[/eluser]
soft_delete_key is for the name of the field you are going to use for storing the deleted status for the records.

So that when you do a delete, it will use the following to update the table
Code:
$this->db->update($this->_table, array( $this->soft_delete_key => TRUE ));
On get when soft delete is used Jamie's code he uses this
Code:
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
        {
            $this->db->where($this->soft_delete_key, FALSE);
        }
To check to see if the soft_delete is being used and if it is adds the where statement to exclude the deleted records
#4

[eluser]xtremer360[/eluser]
I'm still confused because it should be doing where the where as where title_status_id is NOT the soft delete value.




Theme © iAndrew 2016 - Forum software by © MyBB