> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Emile
> 
>         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.

Ah! In order to avoid the naming clash, an alias must explicitly be set
for the second relation, e.g.:
        step4.setAlias("insrel2");

This is essentially analogous to the way an alias has to be used when
you would write the SQL-statement yourself.

Rob van Maris
Technical Consultant

Quantiq
xmedia & communication solutions

Koninginneweg 11-13
1217 KP Hilversum
 
T    +31 (0)356257211
M    +31 (0)651444006
E    [EMAIL PROTECTED]
W   http://www.quantiq.com


Reply via email to