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.

Related entries woes

October 26, 2007 9:19pm

Subscribe [2]
  • #1 / Oct 26, 2007 9:19pm

    wsmith

    13 posts

    I guess the title should really be “Related Entry woe as you can really only relate to an entry to one other entry, as far as I can tell. The only way I can get anything like a one to many relationship is via reverse related entries.

    I’m glad there is a If_no option in both the related and reverse_related entries tags—but I don’t want anything to show up if there are no entries(I know this is doable via the “if no related” tag), and i only want a header if there ARE related (or reverse related) entries. As far as I can tell, you can’t have a conditional header if there ARE related entries, is that correct?

    Also I don’t understand why have a limit on something like a gallery if it can only be related to one gallery entry.

    Am I just confused? or should this be a feature request, or is there a well known work-around that I haven’t found?

    thanks all,

    ward

  • #2 / Oct 28, 2007 10:49am

    Robin Sowell

    13255 posts

    I suspect some of it may be a feature request.  But there are some workarounds.  With the related fields- if there’s nothing related, that field value will be 0.  So if you need a conditional for that, you can use:

    {if related_field != 0}
    There is a related entry
    {/if}

    For the reverse related, try using the count conditional- here’s a nice example by AJP.

    And- good point on the gallery- since you can’t related a gallery entry back to a weblog entry in the same way you can between weblogs, the reverse related isn’t relevant.  But since the syntax is the same regardless, I think that’s the source of confusion.  At least- I think I just confused myself trying to explain it.

    That help- or what bits are still fuzzy?

  • #3 / Oct 30, 2007 4:29pm

    wsmith

    13 posts

    That does help—i’m going to incorporate the !=0 thingy and that should be cool.

    I am noticing that even the If no reverse related tag doesn’t return my text, so dunno what is up with that.

    And finally(!) to be clear, am i understanding it correctly that related entries to a gallery can only link to one gallery image, not the entire gallery?

    thanks for your help,

    ward

  • #4 / Oct 30, 2007 4:35pm

    Lisa Wess

    20502 posts

    That is correct, it is a one to one relationship. We’ve had some users that use a custom field to store the gallery name, and then nest the gallery entries tag inside the weblog entries tag, or use an embed to pass that information.  You would be best to post a how-to on that if you want to try it out.

  • #5 / Oct 30, 2007 5:20pm

    wsmith

    13 posts

    I have to take back something i said in an earlier post—the {if no related} tag does work—i was unwittingly using an older version of EE.

    however, a small glitch in the workaround suggested above. Because I am needing to use related entries in a one to many situation, i actually have to use reverse_related tags to get a list of articles by someone.

    just on a lark, I tried {if no_reverse_related entries ==0}

    meaning, if there ARE reverse related entries, list all of them. Unfortunately, it works, but repeats the title over each record. Is there no way to get conditional header information if there ARE related entries?

  • #6 / Oct 30, 2007 5:28pm

    Lisa Wess

    20502 posts

    Ward, you just confused me terribly.  Can you try re-phrasing exactly what you need to compare to, and what the output should be?  Do you essentially mean that you need an {if reverse_related_entries}?

  • #7 / Oct 30, 2007 5:40pm

    wsmith

    13 posts

    yeah, sorry for the confusion.

    I have a weblog called “people.” People entries have entries concerning them(not by them) in two other weblogs,  “articles” and “research”

    My basic point is that I am in the page, and there are articles related to a person, I want a headline that says “Articles” (only once) and lists the relevant entries in that weblog. If they don’t have any articles, I don’t want anything to show up.

    because a person can have many articles or research entries, or one, or none, it basically is a one to many relationship.

    the only way to do this in EE that I know of is to use the reverse_related entries tag (related_entries can only handle a one-to-one relationship).

    If a person has an article or a research entry concerning them, I want it to show up on their “people” profile page, with a header.

    There is a conditional we can use in the related and reverse_related tag if there are NO entries, so that a single message is returned, like “There aren’t any related entries” however, there is no way to set up a conditional header if there ARE related entries. I have tried some things that work, but they don’t work like a headline. In other words, if a person has five articles, the “Articles” headline appears five times.

    I still feel like i didn’t explain that very well. please feel free to ask me to restate my case again in case that is true!

  • #8 / Oct 30, 2007 5:47pm

    Lisa Wess

    20502 posts

    How about using something like:

    {if count == "1"}

    ? You might also check out this Behind the Curtain entry.

  • #9 / Oct 30, 2007 6:14pm

    wsmith

    13 posts

    YES! i didn’t realize there was a count thingy(technical term) in there.

    Thank you Lisa, the solution for my problem was this, as you suggested:

    {reverse_related_entries sort="asc" weblog="articles" orderby="title"}
    {if no_reverse_related_entries} {/if}
    {if no_reverse_related_entries ==0}
    {if count ==1}
    <H1>Articles</H1>
    {/if}
    {/if}

    {title}

    {/reverse_related_entries}

    strange because of the necessity of the double negative, but true.

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

ExpressionEngine News!

#eecms, #events, #releases