在Doctrine\ORM\PersistentCollection中定义自定义方法 [英] Define a custom method in Doctrine\ORM\PersistentCollection

查看:78
本文介绍了在Doctrine\ORM\PersistentCollection中定义自定义方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以多对多关系获取数据,我想定义自定义方法。是否可能(以及如何)使用以下内容:

  $ hotel = $ entityManager-> getRepository('Hotels') - > findOneById(1); 
$ types = $ hotel-> getTypes(); // $ types是** Doctrine\ORM\PersistentCollection的实例**
$ types-> myCustomFunction(); //做某事


解决方案

似乎没有实现。



看到这个Doctrine的JIRA问题: http://www.doctrine-project.org/jira/browse/DDC-547


考虑允许自定义PersistentCollection实现



我们应该考虑允许在每个关联的基础上配置自定义PersistentCollection实现。
这可以允许用户为一些集合提供优化的(SQL)行为,以提高性能,而无需更改域模型代码。



为此,PersistentCollection需要设计为继承。



I'm fetching data with a many-to-many relationship and I want to define acustom method. Is it possible (and how) to use something like:

$hotel = $entityManager->getRepository('Hotels')->findOneById(1);
$types = $hotel->getTypes(); //$types is instance of **Doctrine\ORM\PersistentCollection**
$types->myCustomFunction(); //do something

解决方案

It seems to be not implemented already.

See this Doctrine's JIRA issue : http://www.doctrine-project.org/jira/browse/DDC-547

Consider allowing custom PersistentCollection implementations

We should consider allowing the configuration of custom PersistentCollection implementations on a per-association basis. This could allow users to craft optimized (SQL) behavior for for some of their collections to improve performance without changing the domain model code.

For this, PersistentCollection needs to be designed for inheritance.

这篇关于在Doctrine\ORM\PersistentCollection中定义自定义方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆