在域模型中获取对象相关对象

How to take care of fetching related objects of one object? For example object project has some tags. How and when should I fetch those object? In user initialization in mapper? That would be a big overload. The best way would be to load them dynamicly when system ask user for tags, but how to do that if model does not know anything about the mapper? Or just use Doctrine and forgot all about those problems?

Im asking this in relation to PHP Zend Framework. But any technology would suffice I think for this problem.

It is difficult to answer your question because you are not referring to a specific ORM or framework. If you are looking for suggestions, I would recommend using Doctrine as the model API and Zend Framework as a stand-alone library.

If you need a full featured framework you can take a look at any of these:

  1. Symfony2
  2. CakePHP
  3. Zend Framework (as a framework vs stand-alone lib)
  4. CodeIgniter

If you choose to go with Doctrine as your ORM, you can setup the schema file to ensure objects are relationship aware, then you can make references like:

// Joins tags table by way of intermediary object_tag table providing
//  a M:1, 1:M relationship
$tags = $object->getTags();

Doctrine (1.2 not sure about 2.x) does employ lazy loading pattern, where the objects are only queried when requested.