if there is a way to use the relation (or table) alias instead of defining a prefix for the query.columns (in this example the same as for the table) ?
I noticed when using a relation for a join it’s always done as a LEFT OUTER JOIN, correct?
var query = datasources.db.hades.profile_positions.createSelect();
var pp = query.columns;
query.result
.addPk();
/** @type {QBJoin<db:/hades/persons>} */
var join1 = query.joins.add('profile_positions_part_of_an_educational_description_for_persons', 'p');
var p = join1.columns;
/** @type {QBJoin<db:/hades/class_members>} */
var join2 = query.joins.add('_profile_positions_a_party_to_class_members', 'cm');
var cm = join2.columns;
query.where
.add(pp.period_school_year.eq(scopes.globals.plcSelectedPeriod.split(' ')[1]))
.add(pp.period_fraction_name.eq(scopes.globals.plcSelectedPeriod.split(' ')[0]))
.add(pp.profile_definition_level_number.eq(scopes.globals.plcSelectedClass.split(' ')[0]))
.add(cm.class_sign.eq(scopes.globals.plcSelectedClass.split(' ')[3]))
.add(pp.profile_definition_subject_code.eq(scopes.globals.plcSelectedSubjectCode))
.add(pp.profile_definition_subject_type_code.eq(scopes.globals.plcSelectedSubjectTypeCode));
query.sort
.add(p.name.asc)
.add(p.first_name.asc);
var dataset = databaseManager.getDataSetByQuery(query, -1);
foundset.loadRecords(dataset);
The first table doesn’t need a type definition because its created by datasources.db.hades…createSelect() in this case servoy knows the datasource.
For the datasource/relations the way they are added in the sample is that its based on a string (datasource/relation). If you like to add them this way it is needed to use the @type.
You can also directly use servoy relation, if you do its not needed to use @type.
var query = datasources.db.svy_sample.contacts.createSelect();
var join1 = query.joins.contacts_to_addresses;
query.result.addPk();
query.result.add(query.columns.name_last);
query.result.add(join1.columns.zipcode);
query.sort.add(join1.columns.zipcode.asc);
var result = databaseManager.getDataSetByQuery(query,-1);
You can use other join types.
You can do that by setting it as a second argument the alias will then be the third argument.
Thanks for your info. I have also hoped on a solution to use the table alias as column alias (as with standard SQL statements), to avoid the query or join variables. Yes I know if I do write them explizit with every column I don’t need the variable, but that is a bit confusing. The table alias seems only to be used internally (can be seen when outputting the QB Select or in debugger).
You can’t expect the compiler to offer code completion on some string you set somewhere (like ‘myAlias’). But how is the effort of setting an alias different from pulling the join into a variable? If I understand you right, you want
patrick:
You can’t expect the compiler to offer code completion on some string you set somewhere (like ‘myAlias’). But how is the effort of setting an alias different from pulling the join into a variable? If I understand you right, you want