Needs work
Project:
Relation
Version:
7.x-1.x-dev
Component:
API
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
7 Oct 2011 at 17:53 UTC
Updated:
15 Jan 2018 at 17:45 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
erikstarck commentedI'm having a similar problem and I'm getting this message in the error log:
2.822 ms Evaluating the action entity_delete. [edit]
7.161 ms There is no information about how to delete entities of type relation.
I guess you have to use the Views Bulk Operations-module. Will give it a try.
UPDATE: OK, I added a field to the array in relation_entity_info()
'deletion callback' => 'relation_delete'
Now I can delete using an action.
Erik Starck
Comment #2
chx commentedComment #3
chx commentedYes, that's what I figured too and committed yesterday.
Comment #4
prodigeek commentedCan you elaborate on the change you made? I'm not completely sure how to implement what you described.
Comment #5
chx commentedrelation action delete an entity of type relation just works.
Comment #6
erikstarck commentedThat's good but now I just upgraded to beta2 and my old actions stopped working. In fact, Drupal crashes.
The web server log says:
Call to undefined function ctools_export_crud_load_multiple() in /var/www/drupal/sites/all/modules/relation/relation.module on line 397, referer: [...]/node/49/edit?destination=admin/content
I get the same error from the new block used to edit relations just when I select the relation type.
The version of Chaos Tools I have installed is the latest RC.
(Sorry if this is getting slightly OT.)
Update: that function is in the latest dev version of Chaos Tools.
Update2: Yupp, installing latest dev of ctools fixed the problem.
drush dl ctools-7.x-1.x-devBR Erik
Comment #7
chx commentedI am changing the project page to warn you that you need ctools dev for this. Cant help they didnt release for so long.
Comment #8
prodigeek commentedSorry, I still need some clarification on how to delete the relation.
How do I get rules to find the relation, specifically, using the trigger of Unflagging a node. User unflags a node, I want to delete the relation that rules created before (When the flag was initially triggered).
I've tried loading related entities, but that just gives me end points that does seem to accomplish anything (that I can figure out). I've tried just removing an endpoint, but that didn't work either.
Thanks so much for the help.
Michael
Comment #9
chx commentedThat's a feature request there, but one that I am not inclined to do. Use Views + VBO for that one.
Comment #10
MStrzelecki_ commentedYou can use user->relation or node->relation relationship in views then add rid field and hide it. Then in rules list should be current-item:rid but there is not.
Comment #11
prodigeek commentedI'm so sorry I kinda keep asking the same question. Basically, I need a bit more help with the step by steps of grabbing the relations list and then doing anything with it. I tried loading it through a rules set, but I don't know what to do with it. I tried fetching UID from the endpoints, but the endpoints are invalid. Similarly, when I load a VBO, I get a series of errors (see below), and when I try actions upon it, it again, won't check against endpoints and won't make fields in the VBO available to me.
Ideally, I'd want to check the UID and NID to see if that pair exists and delete that relation. I understand this is complicated and am happy to take this off-line into email or IM.
I greatly appreciate your help and advice and thank you for your time.
Michael
Comment #12
naught101 commentedwill return the ids of all the relation between those two entities. You can restrict it to a relation type with
you can also add an index to the relation_query() or related() call if you need a specific direction. see http://drupalcode.org/project/relation.git/blob/refs/heads/7.x-1.x:/rela... for docs
Comment #13
prodigeek commentedThank you this code is awesome, though I still have to ask, what do I do with it. I tried just putting it in Custom PHP code in Rules, but again, I'm not sure what to do with it next.
I am asking for a good deal of hand holding. I'm super thankful for the help you've given. I know this is possible and I'm just not experienced enough to be able to figure it out. Again, I thank you all for your help.
Michael
Comment #15
C-3PO commentedI am sorry to reopen the issue. It seems that everyone is happy with the solution, but I just can't figure it out. Drupal.org is where all development takes place and I don't really hope to find a solution elsewhere.
I' m a mere site builder, I know little about PHP and I am very fascinated with all the fun stuff that can be done using Relation and Rules module. Sorry I don't know what to do with the code that closed the issue. Ok, I'm trying to configure VBO view. Instead of one single relation to be deleted I get a list of all relations of this type. Once arguments don't get passed to the VBO, it looks that I need to use the rules to select one particular relation.
Could anyone please please take a few minutes to explain how to do it? The idea is to delete a relation between a node that is being unflagged and and a user who unflags it. I believe there are many site builders that could do with this advise.
Thank you so much for the understanding!
Comment #16
mahmost commentedIt is not about deleting a relation .. It is about querying relations using endpoints, and it is still not working in latest dev, the problem is that there is no "query callback" for the property endpoints.
naught101 made a nice starting point in #12, so I tried to make things work with this initial patch.
It worked for my use case and I didn't make a lot of testing for other ones.
Comment #17
mahmost commentedComment #18
mikran commentedThis is from hook_entity_property_info documentation.
Comment #19
mikavirt commentedHi,
I'm a bit lost with the whole thing. I'm also trying to fetch a relation id in order to delete the entity, but I can't. My relations link users to some nodes, and I have relation rc4.
When I implement a "rid" (relation id) field in views, it returns 0 (or null I guess). Same with a relation type field...
How did things evolved since january? How could I manage to get this ID? Would the dev version be a better choice?
Thank you very much!
Michael
Comment #20
miromarchi commentedI'm also a non programmer. I tried #12 and #16, without any success.
I wish to fetch a relation by the endpoints, having the endpoint-list.
Exactly tha same stated in issue How can I get a relation by the endpoints using the “Fetch entity by property” action in rules? by ptmkenny.
Have anyone succeed in it?
Thank you very much
Comment #21
marcusx commentedEven if it is deprecated patch #16 is working fine.
@miromachi
Here is what to do:
1. Create a list of any entiy
2. Put your endpoints in the list
3. Use the endpoint list to fetch the relation
Here is a demo rule export that works with patch #16
And a screenshot of the rule:
Hope this helps.
Comment #22
miromarchi commented@marcusx That's it! Thanks so much! It works now. Your 3 steps workflow in #21 is working for me. Thanks
Comment #23
miromarchi commentedWorking with "fetch relation by endpoints" action in rules, I found out that it fetches all the relations for the endpoints in the chosen list, even if the list contains only one endpoint.
In this (sub)case, the action fetches all relations pointing to the selected endpoint, whatever the other endpoint.
I believe this behavior is very similar to the action fetch entity by property used with entityreference module. I previously used that one to fetch all nodes referencing a chosen node.
Since I wasn't aware of this ability of the relation module, and indeed I thought only entityreference module had it, I write it here, for others to know.
Comment #24
Paul B commentedI've tried to implement this functionality without the deprecated query_callback by using hook_entity_query_alter similar to the patch for Commerce in #1345890: Allow to query order by states from Rules.
Here it is.
Comment #25
miromarchi commentedHi there. I've tried your patch in #24 and it works.
The only point I got relation reporting a "field validation failed" error. Which doesn't mess up with my rule, nor with the expected behavior.
Rules log says nothing.
Watchdog just says
error relation Field validation failed.Sorry I don't know how to help better.
Anybody else?
Edit: my field validation error was totally unrelated to this issue.
Comment #26
mikran commentedThis needs tests
Comment #27
Ravenight commentedI manually patched #24 into 7.x-1.0-rc4 and it worked for me without any messages in watchdog. Thank you so much for this as I was going crazy trying to get this to work.
Comment #28
Yuri commentedWith regard to the 'fetched' state of the relation:
It appears that "fetch relation by endpoints" only makes the rid available, not the custom fields of the relation through 'entity has field'.
Only after another 'fetch entity by id' then 'entity has field' will show the custom field.
Is this normal behavior or a bug?
Comment #29
Paul B commented"Fetch entity by property" returns a list of entities, not one entity. If you add a loop over the list, you can add an 'entity has field' check on the current list item in the loop.
Comment #30
jantoine commented#24 works great with the latest 7.x-1.x-dev.
Comment #31
gvincke commentedUsing 7.x-1.0-rc5 nor patch #16 neither #24 worked for me, following method described in #21.
Still unable to fetch relations using one endpoint.
Some advices ?
Patching using patch #24 ( git apply relation-query_endpoints-1302788-24.patch ) gave me :
relation-query_endpoints-1302788-24.patch:13: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Do you have explanations ?
Thanks !!
EDIT : #16 worked, but not #24. First fail was due to PHP cache unrefreshed. So my fault :(
Comment #32
Anonymous (not verified) commentedFirst comment here on drupal.org.
Thanks for the interesting Relations module :)
Figured a way to work around the problem. Needs Conditional Rules-module to work.
My case was to separate friends (relation type "friends"). Relation was created with Flags. Separating friends happens when either user Unflags the friendship.
My relation has one extra field "uids" which is Integer-type of field. uids = flagging-user[uid]+flagged-user[uid].
Value is added by the rule that creates the friend-relation.
Logic:
Unflag the flagging user from flagged user >> calculate [uid]+[uid] >> loop through flagging-users friends list calculating [uid]+[uid] from all friends on list >> compare result to first calculation-result >> if match is found, fetch entity by property(uids_field value) and delete entity. >> else, "sorry, problems"
Here is the rule:
Found this issue after multiple trials and errors, didn't try either of the patches.
Thought I'll post this here if it helps anyone with the same problem.
Please let me know if my logic is all wrong there ^^
Comment #33
Paul B commentedRe-roll of the patch in #24
Comment #34
miromarchi commentedI've recently updated my
relation 7.x-1.0-rc4andrules 7.x-2.6modules to the latests (relation 7.x-1.0 and rules 7.x-2.9).I've reapplyed the patch in #33.
I'm writing here to inform that my rules fire correctly and the website is working well.
Anyway the patch has some fuzz and offset against latest relation module.
Thanks once again for the patch!
Comment #35
WidgetsBurritos commentedWorks perfectly for me as well.
Comment #36
oksana-c commentedApplied patch #33 to Relation 7.x-1.0. And followed steps below from #21 to fetch the relation:
1. Create a list of any entiy
2. Put your endpoints in the list
3. Use the endpoint list to fetch the relation.
Happily reporting that relation is fetched successfully and fields that are attached to the relation are accessible within the rule.
BIG thank you for the patch!
Comment #37
javiprada1 commentedHello!!!
I am very happy because thanks to this issues I solved the following problem:
expects parameter 1 to be array, null given en rules_action_entity_query
Thanks oksana-c to simplify the soluction, thanks Paul B for share with us the patch.
Now, I can finish the new rules.
Regards, Javier.
:)
Comment #38
mzvast commentedThank you guys!Your patch #33 solved my problem
PS:don't forget to clear cache after patch!
Comment #39
socialnicheguru commentedComment #40
mikran commentedI still think this needs tests. However here is a reroll, current patch did not apply anymore.
Why it is not using the
related()method ofRelationQuery?