有人可以告诉我如何使用Propel ModelCriteria获取间接相关的类吗? [英] Can someone tell me how to obtain indirectly related classes using Propel ModelCriteria?

查看:91
本文介绍了有人可以告诉我如何使用Propel ModelCriteria获取间接相关的类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能的话,我希望获得社区的帮助.

I'd like some help from the community, if possible.

我们有一个项目在进行中,重构的时机已到.我们正在使用PHP 5和Propel 1.6作为ORM层.这个想法实际上很简单:我们正在尝试同时获取所有相关信息.

We have a project at work, and time has come for refactoring. We are using PHP 5 and Propel 1.6 as ORM layer. The idea, actually, is pretty simple: we are trying to obtain all relevant information at the same time.

但是,此信息并不总是与主类(或换句话说,与主表)直接相关.例如:

However, this information is not always directly related to the main class (or, in other words, to the main table). For example:

return (
$this->leftJoin( "IES.Pessoa mant" )
    ->leftJoin( "mant.Papel subpapel" )
        ->where( "subpapel.tipo = ?", Tipo_papel::IES )
        ->leftJoin( "subpapel.RelacionamentoRelatedByIdSubPapel relm" )
            ->where( "relm.tipo = ?", Tipo_relacionamento::MANTENEDORA_IES )
            ->leftJoin( "relm.PapelRelatedByIdSuperPapel superpapel" )
                ->leftJoinWith( "superpapel.Pessoa iesm" )
                ->where( 'superpapel.tipo = ?', Tipo_papel::MANTENEDORA_IES )
);

这是来自我们模型层的ModelCriteria中的函数代码.这个想法是获得与一个"IES"相关的"iesm".

This is the code of a function in a ModelCriteria from our model layer. The idea is to obtain 'iesm' related to one 'IES'.

但是,这里有一个问题.碰巧"IES"已经与一个实体"Pessoa"相关.因此,当应用此代码时,该对象将丢失,从而为与"iesm"相关的实体"Pessoa"留出空间.

But, here we have a problem. It happens that 'IES' is already related to one entity 'Pessoa'. So, when this code is applied, this object will be lost, giving space to the entity 'Pessoa' related to 'iesm'.

因此,基本问题是:我想在"IES"对象中设置属性"iesm",而不是在Pessoa中设置属性,这是由于Propel映射而设置的.话虽这么说,我该怎么做?可能吗?我想基于在leftJoinWith上创建的别名设置'iesm'.

So the basic question is: I would like to set the property 'iesm' inside 'IES' object, and not Pessoa, which is set because of Propel mapping. That being said, how can I do that? Is it even possible? I'd like to set 'iesm' based on the alias created on leftJoinWith.

然后紧接着显示的另一个问题是:如果数据库中没有直接关系,如何使用相同的想法设置该对象?试图更好地解释:此"iesm"实际上是"Pessoa_juridica"类型的对象.而且"Pessoa_juridica"与"IES"没有直接关系.如何在"IES"对象中设置"Pessoa_juridica"?

And another question, that showed immediately after this: if there is no direct relation in the database, how can I set this object, using the same idea? Trying to explain better: this 'iesm' is actually an object of type 'Pessoa_juridica'. And 'Pessoa_juridica' is not directly related to 'IES'. How could this 'Pessoa_juridica' be set inside 'IES' object?

我什至不知道这是否是使用它的最佳方法,因此欢迎其他任何想法.如果您想进一步说明,请告诉我.

I don't even know if this is the best way of using it, so any other ideas are welcome. If you want further explanation, just let me know.

推荐答案

好,所以我认为我无法理解您要处理的内容:您可以优化数据库连接的内容,但是发现,因为您需要将两个不同的不相关的表与另一个连接一种以某种方式加入他们的行列.

Ok so i think i undestand what your are dealing with: You what to optimize database connections but found that, because you need to join two different unrelated table with another one that joins them in some way.

在这种情况下,我的建议是:

My advise in this situation is:

  1. 尝试将UNION与自定义查询一起使用.因此,创建两个条件并使用UNION合并结果,这将使两个表中所选字段的大小和类型相同,以使其起作用.我不确定如何使用查询objets来做到这一点,但是我很确定可以使用Peer类来实现.选中此链接使用Propel ORM进行UNIION查询

不要隐藏所有对象.有时,使用语句(如doSelectStmt())效率更高,更清晰得多,并且可以从单独的数据库查询中获取信息作为数组,对它们进行操作,然后仅合并将要使用的对象.

Dont hidrate all objets. Sometimes its far more efficient and quite more clear to use statements (like doSelectStmt()) and fetching information as arrays from separate database queries, manipulate them and then only hydrate the objects you are going to use.

请记住,symfoyn还具有一个缓存(例如APC),当处理非常大的表,复杂的信息和重复的信息时,这总是一个好主意.

Remember that symfoyn also has a cache (APC for example), that's always a good idea when dealing with really big tables, complex information and repeated information.

这篇关于有人可以告诉我如何使用Propel ModelCriteria获取间接相关的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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