[Dbix-class] help building query w/ ->search() or using arbitrary select?

George Hartzell hartzell at alerce.com
Wed Aug 9 19:28:40 CEST 2006


Matt S Trout writes:
 > George Hartzell wrote:
 > > I think that I understand that I can do something like this:
 > > 
 > >   { join => {nodes => attrs}}
 > > 
 > > to get at <node_attr>'s that belong_to <node>'s that belong_to an
 > > <rn>.  But at this point I no longer know how to get the rn and rncbt
 > > join that I achieved in the example above with the simple:
 > > 
 > >   { join => 'rncbts' }
 > > 
 > > Is there a way to do both?
 > > 
 > > And even goofier, I'm working with pairs of nodes and contraining on
 > > their node_attr's, so I think I need to do this:
 > > 
 > >   { join => {nodes => attrs,
 > >              nodes => attrs}}
 > > 
 > > which I think should give me attrs and attrs_2 that belong to node and
 > > node_2 that belong_to <rn>???
 > 
 > join => [ 'rncbts', { nodes => 'attrs' }, { nodes => 'attrs' } ]

Holy Mackerel:

  my $rs = $s->resultset('...')->search({
                                          'node_count(me.id)' => 2,
                                          'control_count(me.id)' => 1,
                                          'attrs.name' => 'NodeType',
                                          'attrs.value' => 'Protein',
                                          'attrs_2.name' => 'Organism',
                                          'attrs_2.value' => 'Homo sapiens',
                                          'attrs_3.name' => 'NodeType',
                                          'attrs_3.value' => 'Protein',
                                          'attrs_4.name' => 'Organism',
                                          'attrs_4.value' => 'Homo sapiens',
                                          'rncbts.value' => 'Protein',
                                          'rncbts.count' => 2,
                                         },
                                         {
                                          join => [{nodes =>
                                                    ['attrs', 'attrs']},
                                                   {nodes =>
                                                    ['attrs', 'attrs']},
                                                   'rncbts',
                                                  ]
                                         },
                                        );


which says that attrs and attrs_2 belong_to one node, and attrs_3 and
attrs_4 belong to the other.

wow.  yeesh.

Yeah, I'm getting the 'two nodes of type Protein' constraint twice,
once from my rncbts table and once by contraining the node_attr, but
it's on the way to something even more powerful/ugly/goofy.

Thanks!

g.



More information about the Dbix-class mailing list