Say I have the following allowed value options:

1|Red
2|Purple
3|Blue
3|Green

Blue and Green will not be searchable because they share the same key value. Is there any way around this?

Comments

gthing’s picture

Further testing shows only the last option with a given key value will be searchable. In the case of my example above, you will be able to search for Green but not Blue. If you add another line like 3|Yellow, then both Blue and Green will be unsearchable and you will only be able to search for Yellow.

markus_petrux’s picture

Status: Active » Closed (works as designed)

This key should be unique. It is the same with nodes or users, for example, you cannot have more than one node with the ID equal to 3, or you cannot have more than one user with the ID 3.

Here the last value wins. See:

// PSEUDOCODE

For each row in the list;
  $array[$key] = $value;
End

Each time $key is 3, the $value is stored in the same element of the array. So last value wins.

gthing’s picture

In my case I am storing values for calories burned per hour for exercises. Two exercises might burn the same amount of calories. It seems like overkill to do exercises as nodes and use a node reference field. Is there a workaround?

markus_petrux’s picture

The exercise is your entity here, and number of calories and hours are properties of that entity. The entity needs a key that gives a unique value for each exercise. There are several methods to do it. The most common one is using auto incremental keys, another method is to generate random keys with an algorithm that does not generate duplicates.

Because you need to manage two properties for each exercise, you need a container that is able to do that, for example a node + cck (Drupal 6), or there are other "fieldable" entities in Drupal 7.

PS: this issue is kind of beyond the scope of this module.