为嵌套实体实现存储库

时间:2014-12-12 10:11:47

标签: php orm ddd-repositories

我正试图解决这个问题。尝试在具有复杂域逻辑的项目中实现存储库时,会出现一些问题。

说,你有博客,有帖子,有评论。

所以我创建了一个PostRepositoryInterface。

interface PostRepositoryInterface 
{
    public function findAll();

    public function findOneById($id);

    public function save(Post $post);
}

然后我为NiceORM做了Post Repository实现。

class NiceORMPostRepository implements PostRepositoryInterface {
     // Stuff
}

现在的问题是如何处理嵌套的注释。

我找到了一些答案,比如在界面中添加方法:

interface PostRepositoryInterface {
    // Old stuff

    public function findAllWithComments();
    public function findOneByIdWithComments($id);
}

我觉得这种方法存在问题,特别是当实体增长并且嵌套实体的数量增加时。

我也想知道你对保存这些复杂实体的意见。

假设我们有翻译的帖子,我们处理翻译的方式就像......

$postQuery->withLanguages();
$post = $postQuery->findOne();
$post->language('en')->setTitle('Nice Post Title');
$post->save();

这样可以保存嵌套的实体语言。

如何使用存储库实现此功能?有可能吗?

感谢您的所有见解。

0 个答案:

没有答案