Welcome Guest, Not a member yet? Register   Sign In
model for two tables
#9

[eluser]jared4444[/eluser]
[quote author="waldmeister" date="1262576908"]You can use as many tables per model as you like. True, many out there try to use only 1 table per model, but seriously: Why?

Most of the time 1 table depends on the other (like in your case) and then you have to mix them anyways. I usually have 1 model per controller that deals with whatever tables the controller needs. If there happens to be the same function in multiple models, I create a common model that contains the functions that otherwise would be duplicate.[/quote]

Hi Again, I have a quick follow up.

I have the function below and get a row from my db. I was wondering if you would do two database calls, one to get the row, then one to get the associated rows. If not, how would you combine them into a single call and fill everything you need to fill?

Here is my function. setfromdbrow assigns db columns to variables that I declare in the model.

Also, would you declare an array in the top of the model with nothing in it, just as a place holder?

Thanks

class Item_Model extends MY_model {
var $_tableName = 'Item';
var $name = '';
var $description = '';


//this is from MY_model
//hydrates this instance with info from db
function get($id)
{
$this->db->select('*');
$this->db->where('id =', $id);
$query = $this->db->get($this->_tableName);
if ($query->num_rows() > 0)
{
$row = $query->row();
$this->setfromdbrow($row);
}
else
return false;
}


Messages In This Thread
model for two tables - by El Forum - 01-03-2010, 02:14 PM
model for two tables - by El Forum - 01-03-2010, 03:44 PM
model for two tables - by El Forum - 01-03-2010, 03:48 PM
model for two tables - by El Forum - 01-03-2010, 03:49 PM
model for two tables - by El Forum - 01-03-2010, 03:57 PM
model for two tables - by El Forum - 01-03-2010, 03:59 PM
model for two tables - by El Forum - 01-03-2010, 04:02 PM
model for two tables - by El Forum - 01-03-2010, 04:06 PM
model for two tables - by El Forum - 01-11-2010, 11:43 PM
model for two tables - by El Forum - 01-12-2010, 02:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB