mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
fix(Merge Node): Enrich input 2 fix (#6526)
This commit is contained in:
parent
806d134602
commit
c82c7f1912
|
@ -278,8 +278,8 @@
|
||||||
{
|
{
|
||||||
"json": {
|
"json": {
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"data": "c",
|
"data": "a",
|
||||||
"input": 2,
|
"input": 1,
|
||||||
"text": "foo",
|
"text": "foo",
|
||||||
"tag": "second"
|
"tag": "second"
|
||||||
}
|
}
|
||||||
|
@ -287,8 +287,8 @@
|
||||||
{
|
{
|
||||||
"json": {
|
"json": {
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"data": "d",
|
"data": "b",
|
||||||
"input": 2,
|
"input": 1,
|
||||||
"text": "foo",
|
"text": "foo",
|
||||||
"tag": "second"
|
"tag": "second"
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,12 +132,8 @@ export function findMatches(
|
||||||
fieldsToMatch: PairToMatch[],
|
fieldsToMatch: PairToMatch[],
|
||||||
options: MatchFieldsOptions,
|
options: MatchFieldsOptions,
|
||||||
) {
|
) {
|
||||||
let data1 = [...input1];
|
const data1 = [...input1];
|
||||||
let data2 = [...input2];
|
const data2 = [...input2];
|
||||||
|
|
||||||
if (options.joinMode === 'enrichInput2') {
|
|
||||||
[data1, data2] = [data2, data1];
|
|
||||||
}
|
|
||||||
|
|
||||||
const isEntriesEqual = fuzzyCompare(options.fuzzyCompare as boolean);
|
const isEntriesEqual = fuzzyCompare(options.fuzzyCompare as boolean);
|
||||||
const disableDotNotation = options.disableDotNotation || false;
|
const disableDotNotation = options.disableDotNotation || false;
|
||||||
|
@ -263,12 +259,8 @@ export function mergeMatched(
|
||||||
let binary: IBinaryKeyData = {};
|
let binary: IBinaryKeyData = {};
|
||||||
|
|
||||||
if (resolveClash === 'addSuffix') {
|
if (resolveClash === 'addSuffix') {
|
||||||
let suffix1 = '1';
|
const suffix1 = '1';
|
||||||
let suffix2 = '2';
|
const suffix2 = '2';
|
||||||
|
|
||||||
if (joinMode === 'enrichInput2') {
|
|
||||||
[suffix1, suffix2] = [suffix2, suffix1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[entry] = addSuffixToEntriesKeys([entry], suffix1);
|
[entry] = addSuffixToEntriesKeys([entry], suffix1);
|
||||||
matches = addSuffixToEntriesKeys(matches, suffix2);
|
matches = addSuffixToEntriesKeys(matches, suffix2);
|
||||||
|
@ -279,15 +271,15 @@ export function mergeMatched(
|
||||||
...matches.map((item) => item.binary as IDataObject),
|
...matches.map((item) => item.binary as IDataObject),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let preferInput1 = 'preferInput1';
|
const preferInput1 = 'preferInput1';
|
||||||
let preferInput2 = 'preferInput2';
|
const preferInput2 = 'preferInput2';
|
||||||
|
|
||||||
if (joinMode === 'enrichInput2') {
|
|
||||||
[preferInput1, preferInput2] = [preferInput2, preferInput1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resolveClash === undefined) {
|
if (resolveClash === undefined) {
|
||||||
resolveClash = 'preferInput2';
|
if (joinMode !== 'enrichInput2') {
|
||||||
|
resolveClash = 'preferInput2';
|
||||||
|
} else {
|
||||||
|
resolveClash = 'preferInput1';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolveClash === preferInput1) {
|
if (resolveClash === preferInput1) {
|
||||||
|
|
|
@ -541,14 +541,18 @@ export class MergeV2 implements INodeType {
|
||||||
|
|
||||||
const mergedEntries = mergeMatched(matches.matched, clashResolveOptions, joinMode);
|
const mergedEntries = mergeMatched(matches.matched, clashResolveOptions, joinMode);
|
||||||
|
|
||||||
if (clashResolveOptions.resolveClash === 'addSuffix') {
|
if (joinMode === 'enrichInput1') {
|
||||||
const suffix = joinMode === 'enrichInput1' ? '1' : '2';
|
if (clashResolveOptions.resolveClash === 'addSuffix') {
|
||||||
returnData.push(
|
returnData.push(...mergedEntries, ...addSuffixToEntriesKeys(matches.unmatched1, '1'));
|
||||||
...mergedEntries,
|
} else {
|
||||||
...addSuffixToEntriesKeys(matches.unmatched1, suffix),
|
returnData.push(...mergedEntries, ...matches.unmatched1);
|
||||||
);
|
}
|
||||||
} else {
|
} else {
|
||||||
returnData.push(...mergedEntries, ...matches.unmatched1);
|
if (clashResolveOptions.resolveClash === 'addSuffix') {
|
||||||
|
returnData.push(...mergedEntries, ...addSuffixToEntriesKeys(matches.unmatched2, '2'));
|
||||||
|
} else {
|
||||||
|
returnData.push(...mergedEntries, ...matches.unmatched2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue