API page: http://api.drupal.org/api/drupal/includes!entity.inc/function/EntityFiel...

Minor change, but considering nearly all of the comments provide examples using arrays for the $value parameter, I propose that the doc be changed from:

$value: The value to test the column value against.

to:

$value: The value to test the column value against. Can be a string or an array of strings.

Comments

jhodgdon’s picture

Good idea to make the documentation more clear! However, saying it can be an array of strings does not explain what that would mean, especially since $field can also be an array. I am not sure what the answer is... any idea?

marblegravy’s picture

Not quite sure where the confusion is because I'm only talking about changing the text for the $value parameter, and $field's description at the moment already says:

$field: Either a field name or a field array.

What if the help text for $value became:

$value: The value, or array of values to test the column value against.

Would an example help? There are plenty in the comments:

->fieldCondition('field_foo', 'tid', array('1', '2'))

Checks the tid column for 1 or 2.

->fieldCondition('field_foo', 'tid', '2')

Checks the tid column for only 2.

jhodgdon’s picture

I guess that $field is something representing a single field, which can be either a string or a field array. Then $column is a database column within that field, and $value/$operator define the condition on the column, with $operator defaulting to = if it's a single value, and IN if it's an array (just like standard query conditions).

So... let's make sure the documentation says this. I think the best way to indicate data types is to put data types on all of the parameters:
http://drupal.org/coding-standards/docs#param
http://drupal.org/coding-standards/docs#types

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.