Active
Project:
Views Or
Version:
6.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Mar 2009 at 16:55 UTC
Updated:
26 Oct 2010 at 23:24 UTC
Jump to comment: Most recent file
Great module by the way, the OR on the filter works a treat but I'm having problems with the COALESCE feature.
I'm trying to add Content fields and it always seems to bring through the nid and nodetype for the first content field and as such the COALESCE feature brings back one of those fields before bringing back the next content field data.
Is it me???
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | views_or_handler_field.inc_.patch | 1.55 KB | leon kessler |
Comments
Comment #1
darren ohI don't understand. What order are your fields in?
Comment #2
whirl commentedI think I have the same problem.. I defined some filters using OR, and that's really great! I want a view where the nodes can have one of two types (book or sub_book), so the filter takes care of that.
But then each of these node types has a field to represent its author: author and sub_author, and I would like to show either one of these, depending on the node type. So I used coalesce in the fields as follows:
Node: Title
Views OR: begin alternatives
Content: author
Content: sub_author
Views OR: end alternatives
And I was hoping this would give me a table (my Style is set to Table) with Titles in the first column, and then Author in the second column - where either author or sub_author is used.
I do get the Author column, but it's value is wrong: for type "book" I get the correct "author" value, but for type "sub_book" I always get the text "sub_book" in that field instead of whatever the value of "sub_author" is.. does that make sense?
Comment #3
whirl commentedI have fiddled with this some more (but I don't fully understand the module code, so haven't been able to change it succesfully). But I did discover that the actual query that is generated is wrong.
I have a fairly minimal example: a view with a single filter to select all nodes of type "book" (this is my own content type and it represents actual books with an author etc.)
Then I use the following fields:
Views Or: Begin alternatives
Content: Pages 9999
Content: Author Default
Views Or: End alternatives
This should display the number of pages in a book, and if that is not available I want to see the author (makes no sense at all, just an example).
So I would expect this to generate the following coalesce part for a query:
COALESCE(node_data_field_pages.field_pages_value, node_data_field_pages.field_author_value) AS node_data_field_pages_field_pages_value
BUT what I actually get is:
COALESCE(node_data_field_pages.field_pages_value, node.type, node.vid, node_data_field_pages.field_author_value) AS node_data_field_pages_field_pages_value
So somewhere in views_or_handler_field.inc (I think) where the coalesce bit is generated, too many fields are added... I just can't figure out where :(
Help anyone?
(I've set this back to "active".. not sure if I'm allowed to do that, but I'm afraid if I don't nobody will ever see this message - sorry if this is not the right way to do this)
Comment #4
kmontyI am experiencing the same problem as #3. If the first field is not found, it echoes out the node type rather than the second field.
Comment #5
whirl commentedI just discovered that Views2 can actually do this without the Views OR module (or at least, it can do what I wanted it to do :-)
In basic settings where you select Style: table you press the little button next to that to get the table settings. There you will get a list of all your fields and for each field you can select a column. If you select the same column for both the fields that you want to combine everything is well!
I hope this is of any use to anyone (not sure if this is a new feature or if I just never noticed it before.. probably the latter :)
(and btw, the "filter" part of the Views OR module works great!)
Comment #6
monotaga commentedI'm having this problem, too. Not sure exactly why; it may have something to do with CCK fields. In any case, I needed a quick fix and came up with this pretty dirty one:
I replaced line 102 in views_or_handler_field.inc:
$coalesce[] = "$field[table].$field[field]";with:
if ($field['alias'] != 'node_type' && $field['alias'] != 'node_vid') $coalesce[] = "$field[table].$field[field]";This really isn't the way to address this issue, but I don't have the luxury of time (nor the intimate knowledge of the guts of Views) to explore it further.
Comment #7
leon kessler commented#5
that solution will not bring the same results as using a COALESCE. You would be simply combining two fields together.
If the first field is empty then okay it works the same, but a COALESCE will not return the second field if the first field is not empty.
I'm getting the same issue as everyone else here with COALESCE, but with more unwanted fields being added. Like format for cck text fields, list and data for image fields.
The problem is that the handlers add in the extra fields because they are needed for the display. So they are still technically part of the same field that has been added to a views_or COALESCE.
I'm thinking that simply removing them from the COALESCE would cause problems.
So I've tried a workaround that groups fields with the same name, inserting them as their own COALESCE. So _value, _type, _vid all stay as separate fields.
This isn't working yet, the sql query comes out correctly, but nothing is displayed in views.
I'll try and do a bit more work on this soon. Was hoping for a bit of input from Darren Oh.
Comment #8
leon kessler commentedAfter a bit more tinkering with this, I've come to the conclusion that using a sql Coalesce function on complex fields is perhaps not the best idea. This sort of thing should really be handled by PHP, which ultimately gives you a lot more control.
I instead went for an option of selecting the fields I wanted in Views, and excluding them from display. I then used a Views custom php field to return the first result.
Comment #9
tbudz commentedIs there any way to do a query alter on this, trying to avoid changing this module, or if there is any plans on adapting this patch into next reversion
Comment #10
alanpeart commentedThanks for this. One of those innumerable handy features in Views that I never discovered until now.