【问题标题】:multiple entity type in entity field query实体字段查询中的多个实体类型
【发布时间】:2014-09-05 08:13:25
【问题描述】:

如何在EntityFieldQuery中添加多个entity_type和bundle?

$query->entityCondition('entity_type', 'profile2')
       ->entityCondition('bundle', 'user_profile');

有没有办法做到这一点?

$query->entityCondition('entity_type', array('profile2','user'))
       ->entityCondition('bundle', array('user_profile','property'));

【问题讨论】:

  • 你试过了吗?根据文档,它应该像那样工作。
  • 它适用于单一实体类型。

标签: mysql sql drupal drupal-7


【解决方案1】:

这是不可能的:https://api.drupal.org/api/drupal/includes%21entity.inc/class/EntityFieldQuery/7

此类允许根据实体属性(例如,node->changed)、字段值和通用实体元数据(包、实体类型、实体 ID 和修订 ID)查找实体。 不可能跨多个实体类型进行查询。例如,没有工具可以找到最近一小时内创建的用户编写的已发布节点,因为这需要同时查询节点->状态和用户->创建。

【讨论】:

    【解决方案2】:

    在官方doc

    public EntityFieldQuery::entityCondition($name, $value, $operator = NULL)
    

    地点:

    $name:“entity_type”、“bundle”、“revision_id”或“entity_id”。

    $value:$name 的值。在大多数情况下,这是一个标量。对于更复杂的选项,它是一个数组数组中每个元素的含义取决于$operator

    $operator:可能的值:

    '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS': These operators expect $value to be a literal of the same type as the column.
    'IN', 'NOT IN': These operators expect $value to be an array of literals of the same type as the column.
    'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.
    

    我猜你忘记了接线员!

    【讨论】:

    • 它能解决您的问题吗?如果是,不要忘记将此答案标记为关闭主题的好答案。
    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多