First, Phil, thanks a lot for DMZ. I’m glad I found it, because I liked DM, but I was getting frustrated with its limitations, and you’ve basically done most of what I was starting to plan out in my mind. Best of all, you’ve implemented it all rather well.
That said, I do have some bug fixes to contribute. Since they’re relatively small, I think they should fit in the post just fine, but if it’s not clear, I’d be happy to send a patch or whatever works for you. Maybe you’ve already caught these, but here we go:
(Line 1400)
function _delete($related_field, $arguments)
{
$this->delete($arguments[0], $related_field);
}
This should have a return so we pass through the success/failure when deleting relations.
Next, I believe the array handling in _save_itfk should really be:
(Line 1112)
if(is_array($o))
{
$this->_save_itfk($o, $rf);
if (empty($o))
{
unset($objects[$index]);
}
else
{
$objects[$index] = $o;
}
}
so that any unsets that take place recursively are carried through.
And finally, another ITFK problem that I’m not positive about. I might be wrong about this, but instantiating a related object when relating via ITFK seems to leave out the related object’s ID because of the field collision detection (as the related record’s ID field has the same alias as the ITFK field). The changed code with the instantiation check moved up:
(Line 3726)
foreach ($fields as $field)
{
$new_field = $append . $field;
if($instantiate) {
$property_map[$new_field] = $field;
}
// prevent collisions
if(in_array($new_field, $this->fields)) {
continue;
}
if (!empty($selection))
{
$selection .= ', ';
}
$selection .= $table.'.'.$field.' AS '.$new_field;
}
That way we include the related object’s ID into the instantiation field map, but we still don’t select the matching field in the query. Like I said, this one I’m not positive about. Maybe I’m not noticing something, but it seems to me that this is the way it should work.
Additionally, I hope I don’t sound too critical, but in using DMZ on a site where I sometimes to have instantiate a couple hundred objects for a page (online store with product category galleries with images via include_related), I wasn’t completely thrilled with the performance (which is a downside of DM in general). So, I spent a few hours with a profiler to see if I could get the low-hanging fruit, and if you’re interested in the results of that, I’d be happy to share with you my findings and code changes. There are some significant performance gains that can be had with fairly minor code changes. But those changes would probably be better communicated outside of a forum post.
Thanks again for all your work on DMZ.
Jim