On my site, my relationships have a direction.
For example A -> B is not the same as B -> A.

Is there a way to specify this relationship in this widget?

For example, when I go to edit page A, I don't want its relationship to B to be shown, becuase that will be confusing.
However, when I go to edit page B, I do want to see its relationship to page A.

Is that possible with this widget?

Comments

steveoliver’s picture

Title: Force Relationship Direction when editing node » Do Relation Select fields affect the display of other endpoints?
Status: Active » Closed (works as designed)

Relation select fields only affect the display of one node/entity/endpoint -- the "origin" (i.e. your Node A).

Relations created in Relation Select fields will be displayed only on it's entity (i.e Node A). It is up to you to further display the relation in other ways/in other places (i.e. on Node B). Additionally, Relation Select fields can be displayed on the origin endpoint in a few different ways.

Does this answer your question?

-Steve

steveoliver’s picture

Title: Do Relation Select fields affect the display of other endpoints? » Do Relation Select fields represent directional relations when editing?
Status: Closed (works as designed) » Active

big_smile,

I misread your first post. Changing title to better reflect your issue. I'll have to look into this.

Jorrit’s picture

I am encountering this as well.

I have a directional relationship between the same node type, so from Page to Page.

Op Page 1 I create a relation to Page 2. In the database, the endpoints look like this:

entity_id | endpoints_entity_type |  endpoints_entity_id | endpoints_r_index
1         | node                  | 1                    | 0
1         | node                  | 2                    | 1

When I go to edit Page 2, I see the relation as well. When I save the node, without changing anything, the endpoints table changes to:

entity_id | endpoints_entity_type |  endpoints_entity_id | endpoints_r_index
1         | node                  | 1                    | 1
1         | node                  | 2                    | 0

This is because relation_select_build_entity_keys() always adds the current entity with r_index 0. I don't think that should happen.

Jorrit’s picture

Status: Active » Needs review
StatusFileSize
new3.01 KB

Please see the attached patch. I also fixed relation_select_field_prepare_view() so it doesn't perform a query for data that is already available. relation_select_entity_get_relations() contains a performance problem because it uses relation_query(), but that is part of another issue. Also, hook_field_load() doesn't need to return $items, so I removed that.

Jorrit’s picture

I left in a dpm(), sorry.

ruben_vreeken’s picture

Jorrit, your patch still creates som errors for me:

Notice: Undefined property: stdClass::$relation_type in relation_select_field_insert() (line 720 of /home/ruben/Eclipse Workspaces/Usendes/epst2/sites/all/modules/relation_select/relation_select.module).

EntityMalformedException: Missing bundle property on entity of type relation. in entity_extract_ids() (line 7633 of /home/ruben/Eclipse Workspaces/Usendes/epst2/includes/common.inc).

I'm trying to find the cause.. I'll post more if I find something useful.

Jorrit’s picture

What git version are you using as the base for applying the patch?

ruben_vreeken’s picture

I'm not using git (don't know where to get a git version of modules actually). I just used the branch that gets pulled in with drush and applied the patch you made.

I think I might've just fixed the issue too by the way:

What seems to happen, is that relation_select_field_insert applies endpoints to the relations listed in it's $items argument. But some of these relations (those excluded in relation_select_entity_get_relations) are no longer loaded. The result is a standard object with an endpoints property but nothing else.

Further on in the function, field_info_instances attempts to load fields on the relation by relation_type, but because the relation never got loaded, it doesn't have a type, and the whole thing breaks down. I think I fixed it by checking if the relation was returned by relation_select_entity_get_relations or not.

Now to figure out how to create a patch...

ruben_vreeken’s picture

Jorrit, I just cloned the module with:

git clone --branch 7.x-1.x-dev http://git.drupal.org/project/relation_select.git

And tried to apply your patch with:

git apply --index relation_select-directional-1714110-5.patch

But the patch won't apply. Am I doing something wrong? (the patch is meant for the 7.x-1.x-dev branch right?)

Jorrit’s picture

There have been some commits in the git repository since I made the patch. I will see if I can recreate it, but don't expect it very soon.

ruben_vreeken’s picture

@Jorrit, I'll try to roll a new patch based on your code and the code I added to fix the problem. Perhaps it's enough to mark this issue as fixed.

damien_dd’s picture

I used your patch and had an fatal error sometimes:

PHP Fatal error:  Cannot use object of type stdClass as array in /htdocs/sites/all/modules/relation_select/relation_select.module on line 488

So i change the line:

    foreach ($items[$entity_id] as $item) {
      $relation_ids[] = intval($item['relation_id']);
    }

by

    foreach ($items[$entity_id] as $item) {
      $relation_ids[] = intval( (array) $item['relation_id'] ); // addin array type
    }
aajones’s picture

StatusFileSize
new1.16 KB

This patch fixes one problem for me, but it creates another. I have a directional relationship of "Parent", with the reverse label being "Child." My goal was to see a node's parent and children, when looking at the node. In my form, I have a relation_select field where I choose the "Parent" when editing a resource.

Prior to implementing a patch, my relations were messed up when editing a 'parent' node. The direction of the relationship became reversed on a node save, so that nodes that were "children" were ending up being "parent" nodes.

With the patch from jorrit implemented, the above undesired behavior is eliminated, but the display of the "children" nodes is also eliminated entirely; I can only see 'parent' nodes of the current node, and not its children.

The problem is in the function relation_select_field_prepare_view . It should be left unchanged from the original code.

This patch is applicable against the 7.x-1.x-dev version that's listed on the module's main page (2013-Jul-24)

aajones’s picture

Issue summary: View changes

Is there any progress on this issue? I updated a production site (yes, I tested first), but didn't notice the reversal of the relationship on the nodes until we had edited approximately 300 nodes, which resulted in all of our relationships being messed up. It would be nice to have this issue resolved, so in the case that I accidentally update this module (again), it will not result in such a catastrophe. There are only a few lines of code which need to be changed. Please see my suggested patch, above.

Thanks for the consideration

nadavoid’s picture

Updated the patch of #13 to account for add/edit forms as well as display.

nadavoid’s picture

To address the original question, "when I go to edit page A, I don't want its relationship to B to be shown" no, I don't think this module will do that. It currently allows you to select the *target* of a relation. I think this assumption is baked in in a lot of places throughout the module, but not everywhere. I think that the thing to think about would be to add an option to the field configuration to select wether you want to be selecting targets or sources of relations.

nadavoid’s picture

Reroll of my patch in #15, making it relative to the module root.