Problem/Motivation

Requesting that fields of type "Number" be allowed as the unique mapping target.

Proposed resolution

Remaining tasks

  • Check if list number fields are impossible to act as an unique identifier
  • Automated tests

User interface changes

API changes

Data model changes

Comments

ben.hamelin created an issue. See original summary.

megachriz’s picture

Patches are welcome.

megachriz’s picture

To be able to mark a field as unique, on the FeedsTarget plugin markPropertyUnique() must be called on the field target definition for a specified field column. See \Drupal\feeds\Feeds\Target\StringTarget for an example.

boinkster’s picture

Here's a patch for number and integer fields. I didn't include list types figuring they would not likely be unique values. I ran out of time to add testing (maybe later).

megachriz’s picture

Status: Active » Needs work

Thanks for the patch, @boinkster! Unfortunetaly, it failed to apply. Did you perhaps create the patch against Feeds 8.x-3.0-alpha3? The testbot usually (if not always) tests patches against the latest dev. So in order to create a patch that applies, checkout the latest dev version of Feeds, make your changes, and then create a patch.

Are list number fields not possible to act as unique values? If so, I think the Integer class can keep extending the Number class. Well, even with the current patch Integer can keep extending Number, though it has no direct benefit.

Automated tests are welcome!

karenann’s picture

Here's an attempt at rerolling this patch.

karenann’s picture

Status: Needs work » Needs review

After rerolling this patch and seeing that it passed the 2 tests, I plugged it into my environment and it seemed to work. However, I did not perform rigorous testing.

I did confirm that when setting an integer field as unique in the mapping and importing, any repeated occurrences of that unique field caused the original one to be updated/overwritten with the data of the second occurrence. This is as I would expect.

Thanks, @boinkster and @MegaChriz for the work on this!

caspervoogt’s picture

I just tested the patch from #6 and it did the trick for me

bwoods’s picture

Another confirmation for the patch in #6 - thanks for posting!

caspervoogt’s picture

Status: Needs review » Reviewed & tested by the community
megachriz’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Can somebody confirm that list number fields are impossible to act as an unique identifier? Because if it is possible, then there’s no reason to exclude these.

It would be good to have an automated test for this issue. Who wants to write one?

megachriz’s picture

Issue summary: View changes
Issue tags: +sfdug2020

Tagging issue for Global Contrib Weekend Event at SFDUG. Thursday Jan 23.

And briefly updated issue summary.

kris77’s picture

Thank you so much for patch in #6.

Work for me too.

Thanks @karenann.

megachriz’s picture

StatusFileSize
new6.21 KB

I've tested for which number field types Feeds technically can use them as unique target and I found out that:

  1. Using a field of type "list_integer" as unique works as expected. Yes, for this field you define a limited amount of allowed values, but still... if you want to select an entity on a value in this field, Feeds can do that.
  2. Using fields of type "float" and "list_float" as unique does not work. This is because floats cannot be selected precisely with the 'equal' operator as I read on this question from Stack Overflow: https://stackoverflow.com/questions/1302243/selecting-a-float-in-mysql

Here's a new patch and with some tests. The patch allows "integer", "decimal" and "list_integer" as unique target and it doesn't allow "float" and "list_float" as unique target. No interdiff because I did not start with the previous patch in this issue.

I think this is ready (if it passes tests).

megachriz’s picture

Fixing coding standards. No functional changes were made.

  • MegaChriz committed b639da9 on 8.x-3.x
    Issue #2918222 by MegaChriz, karenann, boinkster: Use Number fields as...
megachriz’s picture

Status: Needs review » Fixed

Committed #15.

kris77’s picture

Thank you so much @MegaChriz.
your job is perfect for me.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.