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.

Help with Parents/Reverse Related Entries Please.

May 20, 2014 9:53am

Subscribe [2]
  • #1 / May 20, 2014 9:53am

    matchlessamp

    14 posts

    Overview of what I’m trying to do.
    I have products and I have artists. I want to relate artists to a product in the artist template and in the product template, show which artists use that product.

    I’m using EE 2.8.1

    The Setup:
    In the Artists channel: {artists}
    The relationship field is: {artist_parent}
    Relates to channel: {products}

    The artists template works great as the admin manually relates products to the artists and everything renders fine. It is in the products template that I am having trouble trying to reverse relate the product to the artist.

    The Product channel setup.
    No relationship field (because it should be reverse related and not create double work).
    So there is no “setup” needed. (right?)

    The issue I think is in the products template:

    <section class="wrapper maincontent">
        <ul class="artist-list">
            {exp:channel:entries channel="artists" orderby="random"}
                <li>
                    {parents field="artist_parent"}
                        <h4>{parents:title}</h4>
    <p>                {/parents}<br />
                </li><br />
            {/exp:channel:entries}<br />
        </ul><br />
    </section>

    This is outside of the Products channel entries loop.

    This does not work. I’ve stared at it and tried many things my eyes have glazed over. Can anyone help me out with this?

    Thanks!

  • #2 / May 20, 2014 10:37am

    Boyink!

    5011 posts

    I think your perspective is off - or I’m not caffeinated yet..😉

    If this code is your Products template, then the channel:entries should be pulling products, not artists:

    <section class="wrapper maincontent">
        <ul class="artist-list">
            {exp:channel:entries channel="products" orderby="random"}
                <li>
                    {parents field="artist_parent"}
                        <h4>{parents:title}</h4>
    <p>                {/parents}<br />
                </li><br />
            {/exp:channel:entries}<br />
        </ul><br />
    </section>

    In other words, you want to loop through the children (products) and find parents (artists) through the relationship field.

  • #3 / May 20, 2014 10:41am

    Boyink!

    5011 posts

    Another stab that might be clearer:

    <section class="wrapper maincontent">
    
    {exp:channel:entries channel="products" orderby="random"}
       {title} - is used by these artists:
      
      {parents field="artist_parent"}
    
             {if parents:count==1}
                 <ul class="artist-list">
             {/if}
                 
             <li><h4>Artist Name: {parents:title}</h4><p></li></p>
    
    <p>            {if parents:count==parents:total_results}<br />
                  </ul><br />
                {/if}<br />
            {/parents}<br />
       <br />
    {/exp:channel:entries}<br />
      <br />
    </section>

  • #4 / May 20, 2014 11:32am

    matchlessamp

    14 posts

    I think your perspective is off - or I’m not caffeinated yet..😉

    If this code is your Products template, then the channel:entries should be pulling products, not artists:

    <section class="wrapper maincontent">
        <ul class="artist-list">
            {exp:channel:entries channel="products" orderby="random"}
                <li>
                    {parents field="artist_parent"}
                        <h4>{parents:title}</h4>
    <p>                {/parents}<br />
                </li><br />
            {/exp:channel:entries}<br />
        </ul><br />
    </section>

    In other words, you want to loop through the children (products) and find parents (artists) through the relationship field.

    Aye… I was the one not caffeinated. I do have the channel as “artists” in my template. Which I should have copy/pasted instead of typing it up.
    :0

  • #5 / May 20, 2014 11:33am

    Boyink!

    5011 posts

    So, it’s working?  Or are you looping artists yet?

  • #6 / May 20, 2014 11:36am

    matchlessamp

    14 posts

    Another stab that might be clearer:

    <section class="wrapper maincontent">
    
    {exp:channel:entries channel="products" orderby="random"}
       {title} - is used by these artists:
      
      {parents field="artist_parent"}
    
             {if parents:count==1}
                 <ul class="artist-list">
             {/if}
                 
             <li><h4>Artist Name: {parents:title}</h4><p></li></p>
    
    <p>            {if parents:count==parents:total_results}<br />
                  </ul><br />
                {/if}<br />
            {/parents}<br />
       <br />
    {/exp:channel:entries}<br />
      <br />
    </section>

    It “seems” to work. I have so many related entries, I wish there was a way in the admin to sort/filter by related entries so I could compare that the right ones are indeed displaying.

    Thanks for the help - this might well be the solution.

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

ExpressionEngine News!

#eecms, #events, #releases