[eluser]OverZealous[/eluser]
Certainly that's easy. Except when you need to add another object type. Or another field to your object. With DM, you can add fields to the DB and have access to them immediately in the object. Of course, it's better to throw them into the validation array as well, but that's a minor thing.
Finally, because it's object oriented, you can start getting really creative with your objects.
For example, say you have a contact with multiple phone numbers, but one number is the "Default". Every time you change the default, you need to unset the previous default. In DM, you can add this to your model:
Code:
// in class Phonenumber
function set_default() {
// gets all other default phone numbers
$others = $this->contact->get()->phone->where('default', TRUE)->get();
foreach($others->all as $o) {
$o->default = FALSE;
$o->save();
}
$this->default = TRUE;
$this->save();
}
Now, that's a few lines of code, but it's associated with the model now. What I like is how clean that is to read when you use it later:
Code:
$phone->set_default();
As opposed to:
Code:
set_default_phone($contact, $phone);
If you aren't used to the OO way of programming, it takes some time to see how it cleans up the code. (It looks like you are more used to functional programming, given your function design ;-))
Also, you don't have to worry about function names too much :cheese:
Finally, I'm not ready to release it yet, but I've developed a really slick way to automatically convert DM objects into form fields or html-ready views. For example, you can get a date-editing field simply by using:
Code:
echo($task->e->datecompleted->date);
And it will automatically print out a date field. With a few minor changes to the DM model, you can even eliminate the ->date at the end. Replacing the ->e with ->v will render the date as formatted text, instead. This only works because of the self-aware nature of DM models.
I've got it working for almost every common DB datatype, as well as some specialty items (like email addresses or web links). The only big caveat is that I've written mine around Dojo and Dijit, which not everyone uses.