Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce:
1) Add the widget to any node
2) Add the related nodes and save
3) Edit the node and rearrange the related nodes
4) Save the node and you will find the the order has not been changed
Any help would be much appreciated!
Comment | File | Size | Author |
---|---|---|---|
#25 | interdiff.txt | 1.47 KB | arturs.v |
#25 | 7.x-1.6-relation-add-weight-1993738-25.patch | 3.62 KB | arturs.v |
#23 | interdiff.txt | 1.14 KB | arturs.v |
#23 | 7.x-1.6-relation-add-weight-1993738-23.patch | 3.3 KB | arturs.v |
#22 | relation-add-weight-1993738-22.patch | 2.73 KB | sdstyles |
|
Comments
Comment #1
nagy.balint CreditAttribution: nagy.balint commentedThis seems to be a valid use case. However it is not so easy to implement.
A possible solution could be to store the weight for each item in the field instance. And then that means that reordering the items in a specific field would only change the order in that specific field, and would not effect other field instances where the relation appears. Also there is a question about how this will play in views, or how we can use the order in views.
Patches are welcome.
Changing version here as well.
Comment #2
gvincke CreditAttribution: gvincke commentedHaving the same problem with relation_add-7.x-1.2
The relation_add field offers a "weight" option that seems to be not recorded in database anywhere. So it's really confusing in terms of UI.
Personally I add a field "weight" to my relations to sort the endpoints with views but then the relation_add field sort them in the added order when I edit. Not user friendly...
Having this real sort option in edit and see mode would be very convenient.
Thanks !
Comment #3
mr.york CreditAttribution: mr.york commentedComment #4
alcroito CreditAttribution: alcroito commentedI'm not sure if this a related issue or not (in case I misunderstood the intents of the issue).
My use case is that I have added a relation_add field to an entity, and set it to unlimited items. When I add a few items, and try to reorder them, the order isn't saved.
The attached patch against 7.x-1.2 adds an rid field to the field table, which lets us run a sort on weights when loading the field data.
In views I then add the delta field to sort the relations, but it causes some duplicates which I then fix by doing a views query alter hook, to add additional constraints on the join clause.
This is a dirty approach, but I haven't thought of a good relationship handler that would be able to fix this, because it depends on multiple tables at once (in my case the field_data_{relation_type} table, user table (where the field is attached) and the relation table).
Hopefully this is a starting point for this issue.
Comment #5
potassiumchloride CreditAttribution: potassiumchloride commentedI have the same issue, and I think this is a support request, not a feature request.
If the relations are draggable in the node/edit then it is safe to assume that most users will expect any changes to the order be saved.
Comment #6
alcroito CreditAttribution: alcroito commentedIt is true that people will expect that, but the actual code does not account for this, so you can consider it a bug, or a feature depending how you look at it.
The patch I attached should let you save the order, although the order will not be used anywhere at the moment.
Comment #7
potassiumchloride CreditAttribution: potassiumchloride commentedThanks for that patch. In my use case, this issue may make Relation Add unusable because I would have to put up warnings to the client that say: "Reordering these items by dragging them does not affect the display order." And, the display order is very important to them. Yes, I could add a field for order #, and they would have to fill that in, but it doesn't change the fact that the intuitive method - dragging the items into an order - would have to be ignored by users with different skills and tolerances.
Comment #8
potassiumchloride CreditAttribution: potassiumchloride commentedI have tried the method described by @gvincke. I added a "Display Order" field to my relation types (to serve as the weight), and I try to use that in views to order the related nodes on the display side. This method works fine when A <--> B (order=1) and A <-->C (order=2). On A, I see the related nodes listed as:
B (order=1)
C (order=2)
But if B <--> D (with order 3) or if B or C are related to any other nodes with the same relation type, the display on the A page breaks. Then it shows:
B (order=1)
C (order=2)
B (order=3)
Testing reveals that setting the node <--> relation Relationship to "avoid node duplication" gets rid of the duplicate but then it does not display or utilize the Order field anymore. So, I can have ordered nodes with duplicates or unordered nodes with no duplicates.
I would try the patch and go that route as a next step, but I don't know enough to be able to understand @Placinta:
Please help.
Comment #9
alcroito CreditAttribution: alcroito commentedHonestly I can't help you much but post the code I used, and as I warned, it is a very dirty approach to solving the problem, and the code is specific to my use case.
I had a simple relation type that connects a user object (profile) and a node object (course), so the relation contains data for each profile and course. With the attached patch I was able to add delta values to the field tables, and with the below code I modified the views queries to filter on the relation id's to eliminate the duplicates.
Comment #10
adam-delaney CreditAttribution: adam-delaney commentedI would agree that if the weight and draggable handles are available in the widget the order should be preserved and available to use in other modules like views.
Comment #11
Cale Bierman CreditAttribution: Cale Bierman commentedI changed the version as the patch from #4 no longer applies cleanly to the dev release
Comment #12
doitDave CreditAttribution: doitDave commented+1 for #10, please consider this a severe issue (also because the module is bitterly needed for serious work with relation at all). :)
Comment #13
osopolarMaybe the delta from the field relation_add could be stored in relation endpoint.
See #1304196: How should we do weighted Relations? #21
Or the weight patch from #20 could be used
Comment #14
Chewie CreditAttribution: Chewie commentedDon't agree that weight of relation should be stored in relation entity base table. Weight is the attribute of entity where relation have connection
Updated patch for 1.5 version
Comment #19
Chewie CreditAttribution: Chewie commentedComment #20
Chewie CreditAttribution: Chewie commentedComment #21
azinck CreditAttribution: azinck commented#20 does not apply against HEAD, nor does it apply against 1.5.
Also: I'm rather unclear about what #20 is trying to do. Where is the delta info going to be stored, Chewie?
Comment #22
sdstyles CreditAttribution: sdstyles at FFW commentedThis patch is fixing weight order issue on latest
7.x-1.x-dev
branch, you won't be able to apply it against7.x-1.6
or other previous versions.To patch latest stable version
7.x-1.6
use7.x-1.6-relation-add-weight-1993738-22.patch
Comment #23
arturs.v CreditAttribution: arturs.v commentedI'm testing the 1.6 version of the patch and while it does work with new nodes I'm facing an issue with existing data. The query does not seem to account for items that does not have the weight value set. Here is a modified patch that attempts to get around that problem. In ideal world the hook_query_TAG_alter could maybe be adjusted to do the same thing.
Comment #24
arturs.v CreditAttribution: arturs.v commentedComment #25
arturs.v CreditAttribution: arturs.v commentedI realised that I have made the patch to work with a very specific field in mind. This updated patch works for all fields.