Emile wrote:
> Thanks Michiel
> 
> > You should use addStep only once. The second (and third and ..) time you
> > must use addRelationStep.
> 
> unfortunately I tried that - the code I sent through had gone through many
> variations,
> the code:
>         BasicSearchQuery query = new BasicSearchQuery();
>         BasicStep step1 = query.addStep(templateFields);
>         FieldDefs field_name = templateFields.getField("field_name");
>         BasicStepField field1 = query.addField(step1, field_name);
> 
>         // Add a related step - field taxonomy.
>         MMObjectBuilder taxonomy = mmbase.getBuilder("data_field_taxonomy");
>         BasicRelationStep step2 = query.addRelationStep(insrel, taxonomy);
>         step2.setDirectionality(RelationStep.DIRECTIONS_DESTINATION);
> 
>         // Add a related step - banks.
>         MMObjectBuilder banks = mmbase.getBuilder("banks");
>         BasicRelationStep step4 = query.addRelationStep(insrel, banks);
>         step4.setDirectionality(RelationStep.DIRECTIONS_DESTINATION);
> 
> produces:
> SELECT template_fields.field_name
> FROM mm_template_fields template_fields,mm_insrel insrel,
> mm_data_field_taxonomy data_field_taxonomy,mm_insrel insrel,
> mm_banksbanks
> WHERE (template_fields.number=insrel.snumber AND
> data_field_taxonomy.number=insrel.dnumber) AND
> (data_field_taxonomy.number=insrel.snumber AND
> banks.number=insrel.dnumber)
> 
> notice the two "insrel"s in the FROM portion - that and the fact that I'm
> only adding relations to the query concerns me that the joins are not
> occurring in the right place.


Two insrels in the FROM is ok, because you have three tables, but indeed one should 
have been
aliased to something else then insrel. I wasn't aware that you should do that 
mannually (I mainly
use the 'bridge' query version noadays, which generated unique aliases for these 
things automaticly,
IIRC). I guess you should have done step4.setAlias("isnrel2") or something similar.

I would advice to use bridge interfaces. You'll have security (which you might need, 
because I
suppose your servlet is serving something to the outside world), and a much cleaner 
interface. It is
well possible, even in servlet implementations. I think it is a bit more user-friendly 
too, because
it does some more things implicitely. You also have some utils in 
org.mmbase.bridge.util.Queries.

Michiel



-- 
Michiel Meeuwissen                  mihxil'
Mediacentrum 140 H'sum                [] ()
+31 (0)35 6772979         nl_NL eo_XX en_US




Reply via email to