Welcome Guest, Not a member yet? Register   Sign In
Can a model be more than just a database layer?
#1

[eluser]juddmuir[/eluser]
I've hit a problem using models and attempting to update the database.

If your model is more than just a representation of a database table, then you may have variables in your model that do not exist in the database. So when you come to e.g. update the database using

function update_entry()
{
$this->db->update('entries', $this, array('id' => $this->id));
}

an error is generated if you have a variable that doesn't map to a field. Is the solution to generate TWO objects: one that is the model that you're using, and the other that is the data-model to pass to the db->update function?
#2

[eluser]GSV Sleeper Service[/eluser]
if you want to use an object with db->update, then yes, you will have to make a separate object. from what I understand, codeigniter models are intended to be used as a place to keep your i/o stuff, you're trying to use them almost like an ORM.

you might want to take a look at Doctrine - http://www.doctrine-project.org/ , which can automatically create objects that match your DB.




Theme © iAndrew 2016 - Forum software by © MyBB