I am using 7.x-3.x-dev of download count. I have created a content type with an "attachment" field: it is a field of type File and with widget File. Now I would like to show a page where the author of the content views who has downloaded the content attachments, so I tried to create a view.
My view shows content of type "File". Since I need to show who downloaded the file, I use a relationship with "Download history: User". The query that Views constructs for me is the following:
SELECT file_managed.filename AS file_managed_filename, file_managed.uri AS file_managed_uri, users_download_count.uid AS users_download_count_uid, download_count.id AS download_count_id, users_download_count.name AS users_download_count_name
FROM {file_managed} file_managed
LEFT JOIN {download_count} download_count ON file_managed.fid = download_count.id AND download_count.type = 'file'
LEFT JOIN {users} users_download_count ON download_count.uid = users_download_count.uid
LIMIT 10 OFFSET 0
this shows nothing because of the clause download_count.type = 'file'
In my database all the entries in download_count table are of type 'node' and the description on the database field says that this is ok (The name of the entity type to which the file was attached when downloaded).
If I remove (or if I put it to 'node') that clause from the code, everything works fine.
The interesting code is in download_count.views.inc:
foreach (entity_get_info() as $entity_type => $info) {
$data['download_count']['table']['join'][$info['base table']] = array(
'left_field' => $info['entity keys']['id'],
'field' => 'id',
'type' => 'LEFT',
'extra' => array(
array(
'table' => 'download_count',
'field' => 'type',
'value' => $entity_type,
'operator' => '=',
),
),
);
}It seems to me that $entity_type has the wrong value, but I do not know if it is an error of my configuration or not. I can solve my issue by putting the string 'node' instead of $entity_type, but well I prefer not to do so because is too quick and dirty for my taste.
Thank you for your support!
Comments
Comment #1
WorldFallz commentedthanks for the troubleshooting. I've been working on getting the views relationship right for quite a while. The module stores the entity type of the entity to which the file is attached (when downloaded) but I'm having trouble figuring out how to explain that to views with the views api. it's actually the last bit of functionality I need to complete before creating a release, but i just can't seem to get it right.
still working on it though...
Comment #2
khandra commentedThank you WorldFallz for the update. I'll wait for you to solve the issue :)
In the meanwhile I think I find another issue of the same query.
the query that is constructed is again:
SELECT users_download_count.name AS users_download_count_name, users_download_count.uid AS users_download_count_uid, download_count.timestamp AS download_count_timestamp, file_managed.filename AS file_managed_filename, file_managed.uri AS file_managed_uri
FROM
{file_managed} file_managed
LEFT JOIN {download_count} download_count ON file_managed.fid = download_count.id AND download_count.type = 'node'
As you can see, the query is matching a fid (file id) with the download count.id. As far as I understand it should match with download_count.fid.
Actually I have solved this issue by changing the code of download_count.views.inc as follows:
This solves the issue in my specific case, I do not know if this fix creates wrong behaviours elsewhere.
Thank you for your work.
Comment #3
WorldFallz commentedjust an update, this is being held up for the time being by #1409454: File Usage: Content relationship broken. any effort toward pushing that issue would be appreciated.
Comment #4
thinkyhead commentedIt looks like the loop in download_count.views.inc beginning with
foreach (entity_get_info() as $entity_type => $info) {...}might be trying to do too much. Maybe it can be replaced with a more explicit set of joins, just for the entities you definitely want to associate with. I notice that on my local stage it's doing things like adding a join for wysiwyg.format (the primary id of that table) which is probably not something you need.Comment #5
WorldFallz commentedThanks again thinky for trying!
I've actually removed that entire loop and all joins in my test site atm (I'm just working with the user and file relationships for now) and still have the problem as described in the views issue we've been batting around. I'm sure it's probably something with my views definition, but I'm just at a loss as to what else to try. :-(
Comment #6
WorldFallz commentedthis should be fixed with the views bug fix and updated download_count dev snapshot