1

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

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 )
);

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

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'.

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.

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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
iffs
  • 73
  • 7
  • @diEcho, any problems with the question? – iffs Nov 17 '11 at 11:40
  • there is too much text and in code part , there is also too lengthy variable names. – xkeshav Nov 17 '11 at 11:42
  • Sorry, how can I get this better? These are exactly the table names, I think I could have changed it to letters... – iffs Nov 17 '11 at 11:44
  • 1
    write your question very clear : what u want and what is coming. thats it. – xkeshav Nov 17 '11 at 11:46
  • I've changed the text a bit, see if it's better for understanding. – iffs Nov 17 '11 at 11:54
  • i really have no experience in `ORM`. I just suggest you to ask in propel forum. – xkeshav Nov 17 '11 at 11:56
  • The question is: IES is Pessoa, and is also related to another Pessoa, its 'iesm'. When this code is applyed, the object Pessoa that is IES is overwritten by Pessoa that is 'iesm'. I'd like not to overwrite this information, and actually set in a property called 'iesm' inside IES object. – iffs Nov 17 '11 at 11:57

1 Answers1

0

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. Try using UNION with a custom query. So create two criterions and use UNION to merge results, for this to work the selected fields en both tables should be the same in size and type. I'm no sure how to do this using the Query objets, but i'm quite sure it can be accomplished using Peer classes. Check this link UNION query with Propel ORM

  2. 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.

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.

Community
  • 1
  • 1
guiman
  • 1,334
  • 8
  • 13
  • Thanks for the answer, I am going to try both A.S.A.P. – iffs Nov 17 '11 at 16:02
  • Well, the union idea was interesting, but it seems I can't use union with ModelCriteria, even in Propel 1.6. So let's try the second... – iffs Nov 17 '11 at 16:18
  • Actually, the second advise gave me an idea. I'm trying to mix your idea with ModelCriteria and Propel's Formatters. I will give further details if it works. – iffs Nov 17 '11 at 16:47
  • Unfortunatelly, the row array returned to the formatter does not have all the information I need, again because of propel mapping. Guess I will have to doSelectStmt, which I was trying to avoid, or to obtain this info with separate queries after all. Thanks for the help. – iffs Nov 17 '11 at 17:10
  • Seems like i got you head running huh :P . I'm glad that at leats you have something to get started. Tell me if further question arise – guiman Nov 17 '11 at 17:12