addAttributeRangeToQuery 在我的结果中重复记录

addAttributeRangeToQuery duplicates records in my result

我在查询的第一部分加入了 GeneralJournalEntryGeneralJournalAccountEntry。我现在正在对 MainAccount 进行硬编码,因为我不确定如何正确使用 DimensionProvider class.

query = new Query();

qbdsGeneralJournalAccountEntry = query.addDataSource(tableNum(GeneralJournalAccountEntry));
qbr1 = qbdsGeneralJournalAccountEntry.addRange(fieldNum(GeneralJournalAccountEntry, LedgerAccount));
qbr1.value(queryValue('111111') + '*');

qbdsGeneralJournalEntry = qbdsGeneralJournalAccountEntry.addDataSource(tableNum(GeneralJournalEntry));
qbdsGeneralJournalEntry.relations(true);
qbdsGeneralJournalEntry.joinMode(JoinMode::InnerJoin);


if (_fromDate || _toDate)
{
    qbdsGeneralJournalEntry.addRange(fieldnum(GeneralJournalEntry, AccountingDate)).value(queryRange(_fromDate, _toDate));
    qbdsGeneralJournalEntry.addSortIndex(indexNum(GeneralJournalEntry, LedgerAccountingDateIdx));
    qbdsGeneralJournalEntry.indexIsHint(true);
}



dimensionProvider = new DimensionProvider();
dimensionProvider.addAttributeRangeToQuery(
                     query
                   , qbdsGeneralJournalAccountEntry.name()
                   , fieldStr(GeneralJournalAccountEntr, LedgerDimension)
                   , DimensionComponent::DimensionAttribute
                   , _costCenterNumber
                   , "CostCenter");

我所有的行都被复制了。我想我又添加了 GeneralJournalAccountEntry 数据源,这就是我有这种行为的原因。

我可以检查 while qr.next 部分中的成本中心值,但是..有没有办法使用上述方法正确地做到这一点:addAttributeRangeToQuery?

好的,经过大量的尝试、搜索和再次尝试,我得到了这个:

select firstOnly dimAttr where dimAttr.BackingEntityType == tableNum(DimAttributeOMCostCenter);
dimAttrNameCostCenter = dimAttr.Name;

query = new Query();


qbdsGeneralJournalEntry = query.addDataSource(tableNum(GeneralJournalEntry));

qbdsGeneralJournalAccountEntry = qbdsGeneralJournalEntry.addDataSource(tableNum(GeneralJournalAccountEntry));
qbdsGeneralJournalAccountEntry.relations(true);
qbdsGeneralJournalAccountEntry.joinMode(JoinMode::InnerJoin);

qbr1 = qbdsGeneralJournalAccountEntry.addRange(fieldNum(GeneralJournalAccountEntry, LedgerAccount));
qbr1.value(queryValue('111111') + '*');


if (_fromDate || _toDate)
{
    qbdsGeneralJournalEntry.addRange(fieldnum(GeneralJournalEntry, AccountingDate)).value(queryRange(_fromDate, _toDate));
    qbdsGeneralJournalEntry.addSortIndex(indexNum(GeneralJournalEntry, LedgerAccountingDateIdx));
    qbdsGeneralJournalEntry.indexIsHint(true);
}


dimensionProvider = new DimensionProvider();

dimensionProvider.addAttributeRangeToQuery(query
                                        , qbdsGeneralJournalAccountEntry.name()
                                        , fieldStr(GeneralJournalAccountEntry, LedgerDimension)
                                        , DimensionComponent::DimensionAttribute
                                        , _costCenterNumber
                                        , dimAttrNameCostCenter
                                        , false);

现在可以了!!我刚刚切换了数据源:

  1. 先加GeneralJournalEntry
  2. 添加 GeneralJournalAccountEntry 并将其与其 "mother/father/header" table 或任何它是 :) 连接起来,即 qbdsGeneralJournalEntry.

所以,没有双胞胎了,没有重复。我仍然想知道为什么内部连接的行为是这样的..

明天我也会尝试对 MainAccount 使用 addAttributeRangeToQuery,并摆脱 LedgerAccount 上那个非常丑陋的范围。