Problem/Motivation

My feed is creating content that is identified (as unique) by 2 fields, but just 1 is used in the mapping, resulting in multiple Updates of the same content item for different inputs/fields.

Steps to reproduce

  1. Create a content type "Account" and add 2 fields: name, address
  2. Set name and address fields to be unique (using unique_content_field_validation module).
  3. Create a feed type processing nodes of type Account, with settings: Insert new content items, Update existing content items.
  4. Set Mapping settings:
  5. - Context = account_responses
  6. - New Json source = account.name -> target: field_name
  7. - New Json source = account.address -> target: field_address

Create and import a feed that produces this input:

{
    "account_responses": [
        {
            "account": {
                "name": "xxx",
                "address": "yyy"
            },
            "balance": {
                "denom": "aaa",
                "amount": "111"
            }
        },
        {
            "account": {
                "name": "xxx",
                "address": "zzz"
            },
            "balance": {
                "denom": "bbb",
                "amount": "222"
            }
        }
    ],
    "other_stuff": {}
} 

Get this Output:
Created 1 Response (node 1: name = www, address = yyy)
Updated 1 Response (node 1: name = www, address = zzz)

So you are left with only 1 content item (the second in the input).

Proposed resolution

I'm filing this issue as a bug since by default the module UI allows to mark multiple targets to be unique.
In that case, we should check for a join/concatenation of the values.
Is it even possible?

Remaining tasks

User interface changes

API changes

Data model changes

Comments

kopeboy created an issue. See original summary.

MegaChriz’s picture

Title: Multiple unique mappings are not respected » When using multiple mappings as unique, provide an option to search for an existing entity based on all of them
Category: Bug report » Feature request

How it works now: Feeds loops through all targets that are marked as unique. For each individual target, it checks if an existing entity can be found. The loop gets broken once an entity ID is found.
So Feeds doesn't search currently for a combination of fields, so I guess this would be a feature request.

How could we make that? Creating a query that joins conditions of both targets would be ideal I guess, but also complicated, because each target can implement their own solution for selecting an existing entity. For example, a target could theoretically call an external service to figure out the entity ID. The method getUniqueValue() can be overridden by targets.

An other possibility is that each target provides a list of entity ID's that conform the criteria, and then Feeds inspects the lists to find the entity ID that these targets have in common. However, this can potentially slow down the import process a lot, because the lists of entity ID's that each target finds on their own could be very large.