I have two node types that are related by a node reference. Essentially, content type A is a container, and content type B is an item. For illustration sake, I'll call content A Box and content B Item. the Item has a number of taxonomy terms that are shared with Box. Again for illustration sake lets call them color and size. What I'm trying to do is set up a rule that does the following:

  • On Creation of an Item ( actually before the content is save) check to see if there is a Box that shares both the color and the size of the item.
  • If one exists, assign the new item to that box (via node reference).
  • If one does not exist create the box, then assign the new item to that box.

I'm new to the Rules module, and although it seems really powerful, I'm just not sure that this particular use case is possible. The part that I'm most unsure about is how to check if the box with certain terms exists.

link|improve this question

feedback

1 Answer

up vote 0 down vote accepted

I think doing this with Rules alone, will work if you have a very limited set of nodes. Once you pass 100 or so, then the overhead of all the object wrappers will soon force you to give PHP gigabytes of RAM instead of megabytes, and then set your servers CPU aflame.

I belive an approach that integrates Rules with Views bulk operations however, could do this neatly for you. I have not attemped anything similar myself, but a VBO should be able to query the database for the node, and then if it exists, return it to Rules.

The code approach would be to implement hook_node_presave, query the database with an EntityFieldQuery for a Box node with the right terms, and assign the reference.

link|improve this answer
Thanks for the info, I'll check it out, maybe just doing it in code is simpler, There is one thing about rules that is a little confusing, Is there any way nest them? like an if then else structure. In other words, a way to call different actions based on different conditions? – user379468 Jan 7 at 15:54
I'm not a rules expert, but I believe the answer is yes. That seems like the subject of another question though, no? :) – Letharion Jan 7 at 15:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.