Closed (won't fix)
Project:
Image
Version:
5.x-2.x-dev
Component:
views support
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Feb 2008 at 10:36 UTC
Updated:
21 Dec 2010 at 02:30 UTC
If I add fields to do with the image file (such as filename), the view shows multiple copies of each node, one for each actual derivative image file.
What's needed in the SQL is image_files.filename = '_original'
Going by the Views API docs here: http://drupal.org/node/99564 we need two things: an addition clause, and also to make it an inner join.
This is what works:
'join' => array(
'type' => 'inner',
'left' => array(
'table' => 'image_image',
'field' => 'fid',
),
'right' => array(
'field' => 'fid'
),
'extra' => array(
'filename' => '_original',
),
),
| Comment | File | Size | Author |
|---|---|---|---|
| views.inc_.innerjoin.patch | 752 bytes | joachim |
Comments
Comment #1
drewish commentedwhat if you wanted one of the other filenames?
Comment #2
joachim commentedMaybe we need to add an option for the filename field...
though that field itself doesn't quite do what it says on the tin -- it just returns "_original", "preview", etc.
Getting back several entries per node seems to go against what you expect from Views: one thing per node.
Comment #3
drewish commentedi think the option is the way to go that or offer an inner joined table for each size...
Comment #4
joachim commentedI realised after I commented that a lot of it depends on your use case.
I've only been thinking of using those fields in views to make image galleries of one sort or another.
You might feasibly want to list all the files that are images, and all derivatives, in which case you don't want the inner join -- even though it does sort of go against the grain of Views.
Is that the sort of thing you had in mind?
We can have both kinds of functionality by specifying the table twice, I think -- there's something in the API docs about aliases.
We certainly need the inner join in some cases -- I tried implementing sorting by filename (http://drupal.org/node/204932) and it produces multiple copies of each node which definitely isn't desirable.
Comment #5
dman commentedBump on this.
Thanks heaps for the patch(es) .. I eventually folded it in, but it's a pain that it seems that the current image/views.inc can't deal with it. I see the placeholder code is there, but it's not available in the UI, or working :(
Gosh it's scary messing around with SQL at this level of abstraction!
Plus ... and here's a biggie - views definitions get cached a lot, so every time you make a change in the hook_views_tables(), you also have to re-save the view before it takes effect. Lost an hour on that one!
Comment #6
sunComment #7
joachim commentedNot so much needs work as needs decision...
Comment #8
sunI think at least in D6, we have a dropdown to select the image size, so I guess this won't fix anymore.