entity_metadata_table_query is like this:
/**
* Callback for querying entity properties having their values stored in the
* entities main db table.
*/
function entity_metadata_table_query($entity_type, $property, $value, $limit) {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $entity_type, '=')
->entityCondition($property, $value, '=')
->range(0, $limit);
$result = $query->execute();
return array_keys($result[$entity_type]);
}
But instead of the entityCondition for the $property I think propertyCondition should be used.
I'm attaching a patch for it.
Comments
Comment #1
pcambraComment #2
fagoMakes sense, let's let the test bot run.
Comment #4
pcambraThe problem was that an '=' was being forced, I've added a previous check to see if the $value is an array and then use 'IN' instead.
Fix attached.
Comment #6
pcambraOops, sorry, wrong path
Comment #7
pcambraComment #8
fago>+ $condition = is_array($value) ? 'IN' : '=';
This is not really the condition, it's the operator.
Anyway, the current behaviour the tests are testing is the default behaviour of the db-tng condition using IN for arrays. However, this does not really work if the property value is itself an array, what might occur. So better let's default to '=' like EFQ, while we could add support for some basic operations too. Maybe, based upon based on the operations efq supports?
For just fixing the actual bug, it would suffice to just go with the default '=' for now + to fix the tests to follow that.
Comment #9
pcambraOk, then this one will do it by now.
Comment #11
fago#9: entity-1041240.patch queued for re-testing.
Comment #13
pcambraComment #14
rszrama commentedI noticed another problem with this function during testing related to #1044308: "Fetch entity by property" has a configuration and evaluation problem. The function entity_metadata_table_query() executes an EntityFieldQuery and returns a value from the array without first checking for results. If no entities with the specified property are found, this results in warnings. Attached patch looks to see if results were returned for the request entity and returns an empty array if not.
Comment #15
rszrama commentedDo I count as pcambra's community? : D
Comment #16
fagohm, I'm unsure.. ;)
Anyway, patch looks great! Thanks, committed.