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.

Struggling to get relationships to work..

February 16, 2011 3:37pm

Subscribe [3]
  • #1 / Feb 16, 2011 3:37pm

    CHIEF

    42 posts

    Im sure this is much easier than I am making it out to be.

    I have two Channels:  “product” + “application”

    In a product page, I would like a link to its related application.  So i have created the relationship custom field in the product channel, where there isa drop down displaying the applications.

    I just cant get it to display anything.. not even if I do a conditional to check for no_related_entries.

    here’s my code in the product template, any help would be greatly appreciated.

    {exp:channel:entries channel="product" dynamic="no" disable="categories|member_data|pagination"}    
        
    {related_entries id="application"}
    {app-name}
    
    {if no_related_entries}
      <h2>No Related Entry Available</h2>
    <p> {/if}</p>
    
    <p>{/related_entries}

  • #2 / Feb 17, 2011 3:53am

    John Henry Donovan

    12339 posts

    mark_chief,

    What version and build of EE are you using?

    Are you using any custom statuses?
    Any dates in the future?

    You are missing the closing channel:entries tag above. IS this the case in your template?

    {exp:channel:entries channel="product" status="not closed" dynamic="no" disable="categories|member_data|pagination"}    
        
    {related_entries id="application"}
    {title}
    
    {if no_related_entries}
      <h2>No Related Entry Available</h2>
    <p> {/if}</p>
    
    <p>{/related_entries} <br />
    {/exp:channel:entries}

  • #3 / Feb 17, 2011 4:51am

    CHIEF

    42 posts

    Hi, sorry, it is closed in the template, just not in the above example.

    v2.1.3- Build:  20101220

    No custom statuses.

    Is it correct that the id=“application” is the name of the channel, and {title} is a custom field in that channel?

  • #4 / Feb 17, 2011 3:20pm

    Ingmar

    29245 posts

    No, the id= field should be the field name of the actual “relation” field. It would depend on what you have named it.

  • #5 / Feb 17, 2011 7:54pm

    CHIEF

    42 posts

    Maybe using the relationship method will not work for what I am trying to achieve.

    Id like to be able create a link to a products application in the template.

    I.e Product 1 is linked to application 1.

    Link:  “View this product’s related application”

    Is this possible?

  • #6 / Feb 17, 2011 9:43pm

    narration

    773 posts

    mark_chief, it will work fine - what you want is exactly what database relationships are meant to do, and that’s what EE relationships implement.

    All you have to do is what John suggested: name the Relationship field you made in Product as the id for the related_entries tag.

    Here’s how your code fragment needs to look, given I’ve named the relationship field in product as prod_app. Tests fine on some dummy data, plus or minus a little formatting work.

    {exp:channel:entries channel="product" dynamic="no" disable="categories|member_data|pagination"}    
        
    Product is {prod_name}:
    {related_entries id="prod_app"}
    Yes, {app-name}
    
    {if no_related_entries}
      <h2>No Related Entry Available</h2>
    <p>{/if}</p>
    
    <p>{/related_entries} <br />
    {/exp:channel:entries}

    Regards,
    Clive

  • #7 / Feb 18, 2011 5:54am

    CHIEF

    42 posts

    Thanks Clive,  You were correct i was missing the part where I had to name the relationship field.  It wasnt very clear in the docs. All is working now.  Thanks everyone else too!

  • #8 / Feb 18, 2011 6:18am

    Ingmar

    29245 posts

    Glad to see you’re all set. Please post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases