Hi Rob
Thanks for your reply.
I've tried to wittle down the code to it's simplest possible form, compiled
it and still getting redundant tables in the query - here is the query code.
The full query has 8 tables joined and many fields, so there were many many
lines of code and confusion reigned!
> ... So explain
> in a little more detail what you tried to do - even if you have resorted
> to another aproach afterwards.
What I have tried to do - a query joining a few tables (related tables -
forgive the SQL terminology). It gets confusing when the joined tables have
joined tables and the documentation hasn't solved that for me yet - will
have another read though. I'm hoping my code is wrong :-), but could
someone please point out how one would create a "downstream join" - by this
I mean - table A -> joined -> table B - > joined -> table C, ie. table B & C
join (relation step). All relation steps I have seen in the docs are
against table A.
the code:
// Sql handler that generates SQL strings.
SqlHandler sqlHandler = new BasicSqlHandler(new
java.util.HashMap());
MMBase mmbase = MMBase.getMMBase();
MMObjectBuilder templateFields =
mmbase.getBuilder("template_fields");
SearchQueryHandler handler = mmbase.getDatabase();
InsRel insrel = mmbase.getInsRel();
// Create query.
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");
BasicStep step2a = query.addStep(taxonomy);
BasicRelationStep step2 = query.addRelationStep(insrel, taxonomy);
step2.setDirectionality(RelationStep.DIRECTIONS_DESTINATION);
// Add a related step - banks.
MMObjectBuilder banks = mmbase.getBuilder("banks");
BasicStep step4a = query.addStep(banks);
BasicRelationStep step4 = query.addRelationStep(insrel, banks);
step4.setDirectionality(RelationStep.DIRECTIONS_DESTINATION);
Regards
Emile