I have rule (After saving new content) which loops through a list to create referenced nodes. I am using an approach similar to:

1. After saving new content of type 'story'
2. Create a new entity
Parameter: Entity type: Node, Content type: article, Title: article related to nid..., Author: 2
Provides variables: Created article (article_created)
3. Save entity
Parameter: Entity: [article-created], Force saving immediately: true
4. Set a data value
Parameter: Data: [node:field-myref], Value: [article-created]

The problem I am having now is that only the last 'child' node created is listed on the 'parent' node. Can someone please offer some help as to why only the last node is being referenced?

Rules 7.x-2.7
Entity Reference 7.x-1.1

Thanks for any help!

Comments

paean99’s picture

Here is a draft that may help you

Events: After saving new content of type reference field test
Actions:

  1. Create a new entity - Parameter: Entity type: Node, Content type: Article, Title: article related 01, Author: [node:author]
    Provides variables: Created entity 01 (entity_created_01)
  2. Save entity - Parameter: Entity: [entity-created-01], Force saving immediately: true
  3. Add an item to a list - Parameter: List: [node:field-reference-test], Item to add: [entity-created-01], Enforce uniqueness: true
  4. Create a new entity - Parameter: Entity type: Node, Content type: Article, Title: article related 02, Author: [node:author]
    Provides variables: Created entity 02 (entity_created_02)
  5. Save entity - Parameter: Entity: [entity-created-02], Force saving immediately: true
  6. Add an item to a list - Parameter: List: [node:field-reference-test], Item to add: [entity-created-02], Enforce uniqueness: true

etc.
A loop here would also be a big help.

mikesimmons’s picture

Thank you so much for your reply. I was confusing the Add an item to a list step with Set a data value. Everything works perfectly after adding Add an item to a list instead of Set a data value. Everything also works in a loop.

Thanks again for your help!

paean99’s picture

Glad to be of help.