Hi, thanks for this module, it's very helpful.
I found a bug while creating a view, I needed the view to return the oldest nid for each gallery so I added a relationship but it had no effect.
After inspecting the resulting query I found that the its returning the following:
SELECT node.nid AS nid,
node_node_gallery_galleries.nid AS node_node_gallery_galleries_nid
..
node_node_gallery_galleries is the name of the first relationship, as you can see it's returning the nid field, however in the relationship definition the name of the field with the max (or min) nid has a different alias:
SELECT gid, MAX(ngi.nid) AS maxnid, node.*
So these relationships aren't producing any effect, I could solve this making the following change:
SELECT gid, MAX(ngi.nid) AS nid
I'm attaching a patch that fixes this,
Hope you find it useful.
Comment | File | Size | Author |
---|---|---|---|
#11 | ng3-newest-oldest-1.patch | 1.98 KB | justintime |
#8 | ng3-newest-oldest.patch | 1.94 KB | scroogie |
#1 | node_gallery-1032986.patch | 1.38 KB | javi-er |
Comments
Comment #1
javi-er CreditAttribution: javi-er commentedsorry for the double post.
Comment #2
justintime CreditAttribution: justintime commentedupdating metadata
Comment #3
scroogie CreditAttribution: scroogie commentedIsn't it on purpose to name it differently to not conflict? It's a subquery after all. Perhaps a 'field' => 'maxnid' or something along those lines helps?
Comment #4
javi-er CreditAttribution: javi-er commentedWell the nid field name will not conflict with the main query nid since Views adds the table alias before each field.
I tried what you mention and unfortunately didn't work, I believe that actually the subquery needs to return the original field name in order to work, but then I don't know Views API that deep to be sure about this.
Not sure if there is another property that can be used for defining the field name but I couldn't find any.
Comment #5
justintime CreditAttribution: justintime commentedPretty sure this is accurate. I have to admit that I don't remember the last time (if ever) I tested those relationships. I have verified the bug exists, but haven't tested the fix yet. I'll try to get some time this week to do some patching/committing.
Comment #6
javi-er CreditAttribution: javi-er commentedCool, I'll be happy to test it after you implement the patch it you need.
Comment #7
justintime CreditAttribution: justintime commentedThe patch doesn't work for me either. I'll see if I can't dig into it later tonight and see what's up. Both before and after return a record, but it's not the appropriate one.
Comment #8
scroogie CreditAttribution: scroogie commentedThe problem seemed to be that the node.* overwrote the field again. It's required to be able to return all fields though, so I wrote it out except for nid.
This one works for me.
Comment #9
justintime CreditAttribution: justintime commentedI thought about doing it that way too. It works, but has a major problem. What happens when a contrib module adds a field to the node table? Or node.module from core adds a field at some point? We'll miss it.
If we're going this route, we should at least fetch the schema, and iterate over that eliminating the nid column. If you're busy, I can do that too. I just wanted someone else to arrive at the same (hacky) fix I came up with before I attempted to code it up :)
Comment #10
scroogie CreditAttribution: scroogie commentedI see the point, but do you really think this is worth the effort?
If core adds a column that will be exported as a views field (which it wouldn't at this point), we could release an upgrade.
Comment #11
justintime CreditAttribution: justintime commentedEffort is pretty minimal. I'm attaching a patch that does this.
However, I think I'm doing something wrong. With this, and every other patch in this issue, when I setup the relationship and use a field from it, I do get a result, but it's always the *incorrect* result -- ie it's not the newest or oldest image. Can someone confirm or deny?
Comment #12
scroogie CreditAttribution: scroogie commentedI had the same effect with the other patches, except mine. I got the correct images with that one.
Comment #13
justintime CreditAttribution: justintime commentedWell, now I'm really confused, because I modified your patch to make mine. In fact, we get the same SQL, we just get it in different ways?!?!?
Comment #14
scroogie CreditAttribution: scroogie commentedWell, I just tried it out. Your patch works for me as well. Doesn't it for you?
Comment #15
justintime CreditAttribution: justintime commentedYeah, none of them work. Maybe I'm doing something wrong in the view. Can you post yours so I can compare to what I have?
Comment #16
scroogie CreditAttribution: scroogie commentedSure thing. Are you on Views 3 alpha? Perhaps its another incompatible change. Here is my view:
Comment #17
justintime CreditAttribution: justintime commentedHmm, don't know what I was doing wrong, but your view works for me. I'll commit this and move on with life :)
Comment #18
javi-er CreditAttribution: javi-er commentedNice to this commited :-) both patches worked fine for me.
Thanks for taking a look to it!