silverstripe / silverstripe-populate

Populate your database through YAML files
BSD 3-Clause "New" or "Revised" License
26 stars 24 forks source link

PopulateMergeMatch does not work as expected #15

Open nebucaz opened 8 years ago

nebucaz commented 8 years ago

I expected to be able to update/merge existing records using PopulateMergeMatch as described in the documentation based. I've written a simple example like follows:

_config/config.yml

Member:
  test:
    Email: "test@test.com"
    Password: "password"
    PopulateMergeMatch:
      - Email

I expected the Populate task to merge with the existing record on consecutive runs of the populate task but it throws a validation error:

ERROR [User Error]: Uncaught ValidationException: Can't overwrite existing member #1 with identical identifier (Email = test@test.com))
IN GET /dev/tasks/PopulateTask
Line 852 in framework/security/Member.php

I've posted the sample-project here https://github.com/nebucaz/sspopulate

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29521860-populatemergematch-does-not-work-as-expected?utm_campaign=plugin&utm_content=tracker%2F668165&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F668165&utm_medium=issues&utm_source=github).
Leapfrognz commented 7 years ago

The issue is that $obj = $blueprint->createObject($identifier, $data, $this->fixtures); actually writes the new object. This cant happen if the original being updated a unique index, such as Email with members. Unfortunately FixtureBlueprint is a core class.

jakxnz commented 4 years ago

Can confirm, this is effecting any record with a unique index value duplicated by populate data.

I was expecting the record data to merge without conflicts.

jonom commented 1 year ago

I hit this problem as well so I tried the example from the ReadMe:

SilverStripe\Security\Member:
  admin:
    ID: 1
    Email: "admin@example.com"
    PopulateMergeMatch:
      - 'ID'
      - 'Email'

It doesn't throw the same error but it also doesn't create a member. There is no Member with an ID of 1 or an email of admin@example.com.

I also get a [Notice] Undefined index: MyRelationID when trying to use a has_one in PopulateMergeMatch.