RelationQuery is hard-coded to force the range to be limited to the first 50 results. This should be left up to the user like the default implementation of EntityFieldQuery.

Comments

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new1.88 KB

Patch attached.

chx’s picture

I am very hesitant on committing this. As RelationQuery extends EntityFieldQuery if one is not satisfied with the 0, 50 range per default, it's easy to skip relation_query and just do a new RelationQuery and then call ->range.

mikran’s picture

It was not a long ago that I figured out that it was RelationQuery thas was setting the default range. Initially, as a coder, I quickly checked the RelationQuery class and thought it was just EFQ with the related method. So I agree with Brian here, the class extends EFQ and the added range default looks more like a personal preference that is likely to confuse many.

chx’s picture

Hrm. What about a doxygen patch on relation_query then?

mikran’s picture

StatusFileSize
new853 bytes

I don't think it's as much a problem with relation_query(). What if we move the range from class constructor to relation_query(patch does this)?

chx’s picture

Status: Needs review » Reviewed & tested by the community

Please go ahead and commit this.

mikran’s picture

Status: Reviewed & tested by the community » Fixed

committed

Status: Fixed » Closed (fixed)

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

mikran’s picture

Status: Closed (fixed) » Needs work
Issue tags: +7.x-1.0 blocker

This is not good yet.

Relation API uses relation_query() a lot, without taking care of results beyond 50. For example relation_entity_delete() does that, which means if any entity is part of over 50 relations only first 50 be checked for deletion. So either we remove range() from relation_query as well or convert all occurrences of relation_query to RelationQuery.

chx’s picture

  1. relation_rules_get_related_entities has a relation_query followed by relation_load_multiple. This should use a Rules option, defaulting to 50.
  2. relation_ui_type_delete_confirm uses it for count. Yes, the range can be removed
  3. relation_relation_exists definitely convert
  4. relation_get_related_entity add a range of 1.
  5. relation_entity_delete perhaps convert to batch?
  6. relation_dummy_field_field_prepare_view loads them all. I vote on keeping the 50.
mikran’s picture

Status: Needs work » Needs review
StatusFileSize
new2.43 KB

1. relation_rules_get_related_entities has a relation_query followed by relation_load_multiple. This should use a Rules option, defaulting to 50.

Where can I find that Rules option?

5. relation_entity_delete perhaps convert to batch?

I don't think it's possible to create a batch in hook.

This patch fixes other points

mikran’s picture

#1570510: relation_entity_delete() is unneccesarily destructive. is related issue and relation_entity_delete is being fixed there.

mikran’s picture

Status: Needs review » Fixed

Committed, without relation_entity_delete improvements that is.

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

andyg5000’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review

In troubleshooting why Search API was only loading 50 relations, I realized that the pseudo entity wrapper property for relations calls relation_rules_get_related_entities to load the related entities. This method has a hard limit of 50 as mentioned in above. @chx suggests that the 50 limit be passed as a default rules option (I'm guessing he means rules parameter).

There are three reasons I'm confused here:

1) relation_rules_get_related_entities is NOT defined as a rules action in hook_rules_action_info. Do we need to write an action to call this and have limit as a parameter?
2) If no, relation_rules_get_related_entities is only used to define properties of the entity in relation_entity_property_info_alter(), so why is it in the rules file?
3) If the 50 limit is for preventing potential memory/timeout issues, is the alter below the best way around this situation

/**
 * Implements hook_entity_query_alter().
 */
function MYMODULE_entity_query_alter(&$query) {
  if (!empty($query->entityConditions['entity_type']) && !empty($query->entityConditions['bundle']) && !empty($query->range)) {
    $entity_info = entity_get_info('relation');
    $bundles = array_keys($entity_info['bundles']);
    if ($query->entityConditions['entity_type']['value'] == 'relation' && in_array($query->entityConditions['bundle']['value'], $bundles)) {
      unset($query->range);
    }
  }
}
mikran’s picture

Status: Needs review » Closed (fixed)

This issue was about RelationQuery and relation_query() (and over year old already). Please open a new issue with this.

andyg5000’s picture

attiks’s picture

FYI: Icreated a follow up issue to fix a bug in the dummy field: #2501067: relation_dummy_field_field_prepare_view should not over write existing items