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.

Reverse Related Entries Hates Me

June 26, 2012 9:23am

Subscribe [3]
  • #1 / Jun 26, 2012 9:23am

    Ian Ebden

    312 posts

    Spent few hours this morning wrestling with the {reverse_related_entries} tag. Couple of issues:

    1. Content inside my {if no_reverse_related_entries}{/if} tag gets output – even if there are results to display. In other words, displaying my “no results” message along with each entry returned. Here’s my code (inside a channel entries tag):

    <section id="reviews">
     {reverse_related_entries 
      cache="yes"
      channel="reviews"
      orderby="date"
      refresh="60"
      sort="desc"
     }
     {if no_reverse_related_entries}<h3>There are no reviews available for this tour yet.</h3><p>{/if}<br />
     <article class="review"><br />
      {cf_review_body_en}<br />
      <footer><br />
       Posted by <strong>{title}</strong> on <time datetime="{entry_date format='{DATE_W3C}'}">{entry_date format="%F %j, %Y"}</time><br />
      </footer><br />
     </article><br />
     {/reverse_related_entries}<br />
    </section><!--/reviews-->

    2. Secondly, in a different area of the same template I need to output the total number of reverse related entries. If I use {total_results} I get the correct number, but it obviously loops – e.g. 4 4 4 4. So I’m trying with the Query mod instead, but that also loops in the same way:

    {exp:query sql="SELECT rel_child_id FROM exp_relationships WHERE rel_child_id ='{my_entry_id}'"}
    {total_results}
    {/exp:query}

    Is it possible just to get a non-looping output from either {reverse_related_entries} or the Query mod?

    My brain hurts :( Any help much appreciated.

  • #2 / Jun 27, 2012 1:08pm

    Dan Decker

    7338 posts

    Hi Ian,

    No worries man, we’ll get you on the right track!

    I’ll address the easy one first:

    2. Secondly, in a different area of the same template I need to output the total number of reverse related entries. If I use {total_results} I get the correct number, but it obviously loops – e.g. 4 4 4 4.

    You can use this:

    {if {count} == {total_results}}
     {total_results}
    {/if}

    That will keep the output to one iteration when the count equals the total results, which is when the last entry is reached.

    Now to the noodler. This may seem nit-picky, but let’s try this just to cover the base:

    {reverse_related_entries channel="reviews" orderby="date" sort="desc"}
     {if no_reverse_related_entries}<h3>There are no reviews available for this tour yet.</h3><p>{/if}<br />
    {/reverse_related_entries}

    Now, with that, make sure you call an entry that will result in “no results” and one that should pull in entries.

    What was the result?

    Cheers,

     

  • #3 / Jun 27, 2012 3:22pm

    Ian Ebden

    312 posts

    Thanks Dan. The “total number of reverse related entries” issue is sorted now.

    For the other issue. Using your code:
    - Where an entry has no reverse related entries, I get the expected “There are no reviews…” message. Great.
    - For an entry that does have reverse related entries, I get the following PHP error:

    A PHP Error was encountered
    Severity: Notice
    Message: Use of undefined constant no_reverse_related_entries - assumed 'no_reverse_related_entries'
    Filename: libraries/Functions.php(680) : eval()'d code

    Nearly there?

  • #4 / Jul 02, 2012 10:49am

    Dan Decker

    7338 posts

    Hi Ian,

    For an entry that does have reverse related entries, I get the following PHP error:

    Well, that honestly makes no sense. What version of ExpressionEngine are you using?

    Give this a try for me:

    {reverse_related_entries channel="reviews" orderby="date" sort="desc"}
     {if {no_reverse_related_entries} == TRUE}<h3>There are no reviews available for this tour yet.</h3><p>{/if}<br />
    {/reverse_related_entries}

    And a couple of variations, just to cover the bases:

    {reverse_related_entries channel="reviews" orderby="date" sort="desc"}
     {if "{no_reverse_related_entries}" == "TRUE"}<h3>There are no reviews available for this tour yet.</h3><p>{/if}<br />
    {/reverse_related_entries}

    Try the last bit with and without the quotes around both {no_reverse_related_entries} and TRUE.

    Cheers,

  • #5 / Jul 02, 2012 11:44am

    Ian Ebden

    312 posts

    Hi Dan. I’m running 2.5.2. I get parse/syntax errors (unexpected ‘{’) on those last 2 code ideas.

    Think I have a busted installation somewhere?

  • #6 / Jul 04, 2012 5:23am

    Paul_B

    86 posts

    Hey Ian, I don’t think you have a broken installation, I’m getting exactly the same error here. I’ve tried Dan’s suggestions and also get an unexpected bracket error.

    My full error when using the syntax from the docs is:

    Severity: Notice

    Message: Use of undefined constant no_reverse_related_entries - assumed ‘no_reverse_related_entries’

    Filename: libraries/Functions.php(680) : eval()‘d code

    Line Number: 10

    Think it might be a bug?

  • #7 / Jul 04, 2012 12:42pm

    Dan Decker

    7338 posts

    Hey fellas,

    I wasn’t able to replicate using ExpressionEngine 2.5.2 and this code:

    {exp:channel:entries
     channel='sandbox'
     limit='10'
     status='not closed'
     orderby='title'}
      <h2>{title}</h2>
    <p>  {excerpt}<br />
      {reverse_related_entries channel="related"}<br />
       <hr><br />
       {if no_reverse_related_entries}</p><h3>There are no reviews available for this tour yet.</h3><p>{/if}<br />
        </p><h3>{title}</h3>
    <p>    {re_excerpt}<br />
       <hr><br />
      {/reverse_related_entries}<br />
    {/exp:channel:entries}

    Which gave me this output:

    ...
    <h2>D I Have</h2>
    <p>en us same humanity.</p>
    
    <p>Thus to convincing arguments of humanity, reason; and by completion to be given this either more not for ever come thought outermost not the limits of two opposed judgment of his skill, would eagerly adopt a programme which it can, because all objects. This represen</p>
    
    <p>t-thinking speculative in so far this is presuming to the obligationis. Being self in and out be what is, mere revealed sophy, they former come impossible. Since not assure and determission of our appearances. There are nothing with resort in an absolutely before also the object proofs of the senses wou</p>
    
    <p><hr></p>
    
    <h3>Aring On Thesis First Conditions.</h3>
    <p>altogether view of thing is real favour.</p>
    
    <p>The fate or of inconcepts, and composition can, because; and that commits of our concept of therefore, in its movements procedure, thereby endeavours to fear that existence of the series of thing but empirical solution, that is thus the scepts for a </p>
    
    <p>xchange the absolute totality of itself, we knowledge, new species of appearance of these make it closely cosmological question of any possible law of nature of all chain our thought turn out to bring beings in the narrow limits thus viewed as <br />
    <hr></p>
    
    
    
    <h2>Ex. But As Is</h2>
    <p>econdly, reason.</p>
    
    <p>This really question dialectic place are to be knowledge just also quarrelling with a thin the world eagerly adopt a programme which requiremely surprisin</p>
    
    <p>in each a decept of exists without this exhaustified with represented on therefore, not say, in our among the multitude.</p><h3>There are no reviews available for this tour yet.</h3>
    <p>...

    There has to be some other factor here - what field-types do you have installed that could be affecting this?

    Cheers,

  • #8 / Jul 04, 2012 3:52pm

    Ian Ebden

    312 posts

    Hi Dan. Sorry this is causing such hassle. I have the following field types installed:

    - Assets
    - Low Variables
    - Matrix
    - Textarea (Rich Text)

    All latest versions. Not sure they have much to do with this though since I can’t even get the {title} field through.

    To be honest, I may actually go a different route using either related_entries or maybe even Playa. Reverse related entries is a bit of an overhead, so may move on from it – especially if I can’t resolve this. Going to give it another shot tmrw and will keep you posted.

  • #9 / Jul 05, 2012 3:40am

    Paul_B

    86 posts

    I’m running too many to mention as the site I’m struggling with is an MSM site, so even though it’s probably not using half of them, they’re installed anyway for the other sites… I too may take another route on this I think if it’s going to involve going down the road of disabling extensions etc as that would affect the live site that’s ok!

  • #10 / Jul 05, 2012 4:13pm

    Dan Decker

    7338 posts

    Hey Ian, Paul

    I’ve asked Robin to look into this as well, and she doesn’t see what amiss. Neither of us could replicate the issue on our end using ExpressionEngine 2.5.2

    It just doesn’t seem like something that would be an environmental issue either. Like your PHP version shouldn’t be a factor.

    However, if you want, I can get a direct look at this.

    Cheers,

  • #11 / Jul 10, 2012 7:26am

    Ian Ebden

    312 posts

    Guys. Had a breakthrough. My reverse_related_entries are part of a snippet I’m grabbing using Croxton’s IfElse plugin. Per the suggestion in the docs, I’m wrapping my condition in {no_results} tag to preserve the condition:

    {no_results}{if no_reverse_related_entries}<h3>There are no reviews available for this tour yet.</h3>{/if}{/no_results}

    I’m all sorted! Paul, does that help you at all? Thanks also to Tim Mahoney for steering me in right direction.

  • #12 / Jul 11, 2012 11:58am

    Robin Sowell

    13255 posts

    Aha- that never would have occurred to me, Ian.  Though yes- next step would have been to get access and see it in action, since we couldn’t replicate.

    Thanks for the heads up on what was happening.  Paul- any chance this explains your issue?  If it is still an issue.  If it’s still a sticking point, we may want to take this private so we can see it in action.

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

ExpressionEngine News!

#eecms, #events, #releases