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