Files
Unify/framework/server/collection/collection.queryChildren.js

123 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2025-12-25 11:16:59 +01:00
/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
as published by the ESA.
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
https://unifyjs.org
*/
import querySQL from '../../unify/querySQL.js';
import joinSQL from '../../unify/joinSQL.js';
import tools from '../../unify/tools.js';
export default class queryChildren{
queryType = "select";
type = "collectionQuery"
__className = "queryChildren"
createQuery( joinTableName, joinQuery, id ) {
var query = new querySQL( );
query.type = this.queryType;
query.table = joinTableName;
query.debug = joinQuery.debug;
query.find( this.collection.getLeft() + "_id", id );
return query;
}
createJoin( joinQuery ) {
var join = new joinSQL( joinQuery );
join.table = this.collection.tableName;
join.name = join.table;
join.left.table = join.name;
join.right.column = this.collection.getRight() + "_id";
join.find( "signed", true );
return join;
}
query( joinQuery, filterObject ) {
var object = this.collection.getObject();
var leftTable = this.collection.getParentName();
var rightTable = object.propertyName;
var id = this.collection.getID( object );
if( !id ) {
if( this.collection.parent ) {
var id = this.collection.parent.id;
}
}
var joinTableName = leftTable + "_" + rightTable;
var query = this.createQuery( joinTableName, joinQuery, id );
var join = this.createJoin( joinQuery, join );
if( filterObject ) {
this.collection.filterQuery( join, filterObject )
if( filterObject.search ) {
//console.log("searchQuery", join, filterObject);
this.collection.searchQuery( join, filterObject );
}
}
join.setFilterAddress("./");
query.addJoin( join );
var result = global.database.query( query );
return result;
}
}