ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Cant get related entries to work

December 04, 2011 1:22am

Subscribe [3]
  • #1 / Dec 04, 2011 1:22am

    phpnoob

    21 posts

    Hi,  I cant get the related entries to work for the life of me.  I am following the instructions here http://ellislab.com/expressionengine/user-guide/modules/channel/relationships.html

    Basically i have two channels,  entry and wall.

    In my custom fields for wall,  I have a response relationship field to entry channel, and stuff_to_say custom field.  Here is my code.

    {exp:channel:entries channel="entry" limit="15"}
            <h2>{title}</h2>
    
    <p>        {related_entries id="response"}<br />
                    {stuff_to_say}<br />
            {/related_entries}</p>
    
    <p>        Submitted on: {entry_date format='%M %d, %Y'}<br />
    {/exp:channel:entries}

    And I dont see any related entries…  Should I turn something on in the settings somewhere for related entries to get turned on?  I tried reverse relate entries also,  no dice.  Besides, logically that doesnt make sense.  I am doing a many to one relationship.  And yes, I have data written.

  • #2 / Dec 05, 2011 4:25am

    John Henry Donovan

    12339 posts

    Hi phpnoob,

    What version and build of EE are you using?
    Are you using any add-ons?

    What does the URL of the page you are on look like?

    Do you see the h2 titles?

    Do you have any custom statuses?

    Give this a go

    {exp:channel:entries channel="entry" limit="15" dynamic="no" status="not closed"}
            <h2>{title}</h2>
    
    <p>        {related_entries id="response"}<br />
                    {stuff_to_say}<br />
            {/related_entries}</p>
    
    <p>        Submitted on: {entry_date format='%M %d, %Y'}<br />
    {/exp:channel:entries}

  • #3 / Dec 05, 2011 11:30am

    phpnoob

    21 posts

    Hi John,

    I am using EE v2.3.1 - Build: date 20111017 This is the url to the page http://www.sitename.com/dev/ee/  I dont think this really matters, yet.  I can see the h2 titles properly.

    I tried your code,  but same problem.  However,  I did some experimentation and managed to get it to work by using reverse_related_entries like this.

    {exp:channel:entries channel="companies"}
            <h2>{title}</h2>
    <p>        {reverse_related_entries sort="desc" orderby="date"}<br />
                </p><h3>{title}</h3>
    <p>            {notes}<br />
            {/reverse_related_entries}<br />
        {/exp:channel:entries}

    So the structure is as follows.  Theoretical “companies” is the parent channel.  The child channel “response” will hold all the note data about companies.  Its always many notes to one company,  a many to one relationship.  I am thinking that reverse_related_entries worked because I am joining the children to the parent and not parent to children.  In the latter related_entries would work.  Am I right?

  • #4 / Dec 06, 2011 11:46pm

    Dan Decker

    7338 posts

    Hi phpnoob,

    You are correct. “Many to one” means reverse-related, while “one to many” is equal to related.

    I’m glad you were able to come to a solution on your own. Is there anything else we can do to help?

    Thanks!

  • #5 / Dec 07, 2011 12:16am

    phpnoob

    21 posts

    Hi Dan,

    Thank you for the feedback.  That will be all, you can close the topic.

  • #6 / Dec 07, 2011 12:44am

    Dan Decker

    7338 posts

    Hi phpnoob,

    Excellent. If you need anything in the future, just let us know.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases