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.

Problem with related entries

June 07, 2011 8:28am

Subscribe [4]
  • #1 / Jun 07, 2011 8:28am

    I am having a hard time with the related_entries tag in EE.  It feels very limiting in a one-to-many relationship scenario.  Am I missing something?  Should I opt for a plugin like Playa to overcome the shortcomings of EE’s related_entries tag? http://pixelandtonic.com/playa

    For instance, a town has several related partners in another channel called town_partners.  My primary channel is the towns channel, my secondary channel is the town_partners channel

    I created a custom relationship field in the town_partners channel, it’s called ‘partner_with’. 

    I have a partner entry with a defined relationship for the city of Portland but this code doesn’t return any related entries, am I doing it backwards?  You can see the live template here:  http://ctenergychallenge.com/portland (search for ‘local partners’)

    {exp:channel:entries channel="towns" limit="1" url_title="{last_segment}"}
        {title}
            <h4>Local Partners</h4>
    <p>    {related_entries id="partner_with"}<br />
            {if no_related_entries}<br />
                Coming soon.<br />
            {/if}<br />
            {title}<br />
            {description}<br />
            {website}<br />
            <hr><br />
        {/related_entries}</p>
    
    <p>{/exp:channel:entries}

    Any insight on why this code does not work would be appreciated.

  • #2 / Jun 07, 2011 9:46am

    Matt:P

    277 posts

    Hi snugghomesoftware

    If a partner needs to be related to more than one town, then consider Playa. We’ve used Playa and it does work VERY well for one-to-many relationships.

    If a partner only needs to be related to a single town, then the built in EE relationships will suffice.

    What you’re doing with your current code is looking for Partner entries which Towns are related TO. Instead you should be looking for what Partners are related to a Town. This is called a Reverse Related Entry.

    So your code would look something like this…

    {exp:channel:entries channel="towns" limit="1" url_title="{last_segment}"}
        {title}
        <h4>Local Partners</h4>
    <p>    {reverse_related_entries sort="desc" orderby="title"}</p>
    
    <p>        {if no_reverse_related_entries}<br />
                Coming soon.<br />
            {/if}</p>
    
    <p>        {title}<br />
            {description}<br />
            {website}<br />
            <hr></p>
    
    <p>    {/reverse_related_entries}<br />
    {/exp:channel:entries}

  • #3 / Jun 07, 2011 12:38pm

    Sue Crocker

    26054 posts

    Thanks for the assist, MattP.

    snugghomesoftware, does the information from Matt make sense?

  • #4 / Jun 07, 2011 1:03pm

    Matt:P

    277 posts

    Anytime Sue. Happy to be a part of the community.

    Matt

  • #5 / Jun 07, 2011 2:24pm

    Brandon Jones

    5500 posts

    Thanks Matt. Let us know if that helps, snugghomesoftware.

  • #6 / Jun 08, 2011 6:13am

    Thank you Matt, that nailed it.  I really appreciate you jumping in and answering that!  Thanks to you Sue for following up.

    Ben

  • #7 / Jun 08, 2011 7:04am

    Matt:P

    277 posts

    Pleasure Ben, see you around.

  • #8 / Jun 08, 2011 4:17pm

    Brandon Jones

    5500 posts

    Thanks all! Don’t hesitate with further questions, Ben.

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

ExpressionEngine News!

#eecms, #events, #releases