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.

Query + Reverse Related Entry + Count no longer works in 1.6

June 28, 2007 6:49pm

Subscribe [3]
  • #1 / Jun 28, 2007 6:49pm

    DSite

    18 posts

    I’m working on a portfolio site.  A few months ago, I wrote some query logic that (combined with a little reverse_related_entry magic and the count tag) helped me get the site working the way I intended for it to work. 

    When I recently upgraded to 1.6, that set of logic broke down.  I’ve done a decent amount of troubleshooting by stripping down my code, isolating templates, etc., and I think I’ve found the culprit.  I just don’t know if it’s a bug or if it’s something that I can fix on my end, and I would love some help.

    (An aside to those who have helped me with queries before: This is indeed the same site as this thread, but it isn’t the navigation that has flummoxed me this time.)

    CURRENT SITE STRUCTURE
    I’ll streamline my structure a little to see if I can explain myself clearly.

    1. I’ve got a weblog called “clients” and one called “projects.”
    2. The “projects” weblog contains a custom relationship field (“projectclient”) that allows me to assign each project to a client.
    3. The primary navigation is a list of categories that have been assigned to “projects.”
    4. The navigation links to category pages with a secondary navigation listing the clients that have projects associated with that category.
    5. On those category landing pages, I would like to show the most recent project associated with the top client on the secondary navigation list.

    It is this final point that is no longer working.

    HOW IT WORKED UNDER 1.5.2
    Under 1.5.2, I had written a query that took the category designation from segment_2 and returned the url_title of the client that I wanted to feature. I then fed that url_title to an exp:weblog:entries tag and called up a list of projects associated with that client using a reverse_related_entries tag. Finally, I used an “if count == 1” conditional to display only the first entry from the resulting list of projects.

    Here’s a simplified version of the code:

    {exp:query sql="SELECT DISTINCT url_title as firstclient
         FROM exp_weblog_titles
         LEFT JOIN exp_relationships ON exp_weblog_titles.entry_id = exp_relationships.rel_child_id 
         INNER JOIN exp_category_posts ON exp_relationships.rel_parent_id = exp_category_posts.entry_id 
         INNER JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id
         WHERE exp_categories.cat_name='{segment_2}'
         ORDER BY url_title
         LIMIT 0, 1"}
      {exp:weblog:entries weblog="clients" url_title="{firstclient}" disable="member_data|pagination|trackbacks"}
        {reverse_related_entries weblog="projects"}
          {if count == 1}
            {projectcaption}
          {/if}
        {/reverse_related_entries}
      {/exp:weblog:entries}
    {/exp:query}

    THE PROBLEM
    When I upgraded to 1.6 (build 20070626), the count part of that logic stopped working. My list of projects no longer displays just the first one. Instead, it displays the entire list.

    I discovered the reason for this when I added a {count} tag next to {projectcaption}: each project in the list was given a count of 1.

    I did a little other troubleshooting and determined that it must have something to do with the query, because when I removed the query and hard-coded a url_title into the exp:weblog:entries tag, the count tag worked as expected, and each project entry received a distinct number (1, 2, 3…).

    THE QUESTION
    Why did this stop working when I upgraded to 1.6?  Do I need to construct my query differently, or could this possibly be caused by a bug in 1.6?  Ultimately, how can I get this working again?

    I hope I’ve described this clearly enough, but let me know if you need examples or anything else.

  • #2 / Jun 28, 2007 9:55pm

    Sue Crocker

    26054 posts

    Just a quick note, I don’t have an answer for you yet, but I did pass on the information to the guys. I’ll let you know when I hear anything.

    Thanks in advance for your patience.

  • #3 / Jun 28, 2007 10:05pm

    DSite

    18 posts

    Thanks, Sue. 

    This is for my studio (not a paying customer), which is why I’ve only been able to make time for it here and there.  So I have no problems being patient.  It’s being baffled that eats away at me.  😊

    I look forward to any debafflement from the rest of the EE crew.

  • #4 / Jun 29, 2007 12:51am

    Derek Allard

    3168 posts

    Despite the pains you took to describe this (thanks) I still am having trouble working out what’s going on.  Writing SQL is a bit beyond what we can offer as tech support, but you’ve got me intrigued, so I’m going to move this into how-to, but we’ll stay on it for you.  Could you either PM me CP access, or PM me a data backup of your site so that I can see your setup?  Thanks.

  • #5 / Jun 29, 2007 1:20am

    DSite

    18 posts

    Thanks, Derek.  I sent you a PM with the login info.

    If it seemed like it was just the query, I definitely would have posted in the “How To” area to begin with, but since this code recently worked just fine and since the query still successfully returns the expected result, it seemed to me like there might be more going on here.

    Thanks for your attention to this.

  • #6 / Jul 02, 2007 11:43am

    Derek Allard

    3168 posts

    OK, thanks, got the PM.  I’ll look into this today.  In plain english, is this what you are trying to do - “for each category (ie: wine-packaging) grab every project listed in that category, and then show every client within that project”?

    So

    wine-packaging
    --- Client Wine Box
    ------ Client

    What should I see on portfolio/wine-packaging?

  • #7 / Jul 02, 2007 1:38pm

    DSite

    18 posts

    Hi Derek,

    That’s almost it.  I’ve sent you a PM with a more detailed explanation of what you see on the site.  But the more accurate plain english would be:

    “for the selected category, grab every project listed in that category, then grab every client associated with those projects, then select the first of those clients”

    That said, the query seems to work just fine.  What doesn’t work is the count tag. With this setup, I’m getting an output like:

    Project A (Count: 1)
    Project B (Count: 1)
    Project C (Count: 1)
    Project D (Count: 1)

    when I should be getting:

    Project A (Count: 1)
    Project B (Count: 2)
    Project C (Count: 3)
    Project D (Count: 4)

    Thanks for looking into this.

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

ExpressionEngine News!

#eecms, #events, #releases