Closed (fixed)
Project:
Views (for Drupal 7)
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Jun 2006 at 20:19 UTC
Updated:
21 Jul 2006 at 23:45 UTC
I'm trying to get /view/thisview/search+string to find all nodes of type 'mp3pig' with aggregator2_audio.artist LIKE '%search string%'. I tried to do the minimal to just do an argument, but I'm getting this error. It's not joining the aa table correctly. I looked over the docs, but I need a little boost. Thanks!
Warning: Unknown table 'aggregator2_audio' in where clause query: SELECT count(*) FROM drupal_node node WHERE (node.promote = '1') AND (node.status = '1') AND (aggregator2_audio.artist LIKE '%blah%') in /home/httpd/vhosts/common/drupal_4_7/includes/database.mysql.inc on line 120
Warning: Unknown table 'aggregator2_audio' in where clause query: SELECT node.nid FROM drupal_node node WHERE (node.promote = '1') AND (node.status = '1') AND (aggregator2_audio.artist LIKE '%blah%') ORDER BY node.sticky DESC, node.created DESC LIMIT 0, 36 in /home/httpd/vhosts/common/drupal_4_7/includes/database.mysql.inc on line 120
function mp3pig_views_tables() {
$tables['aggregator2_audio'] = array(
'name' => 'aggregator2_audio',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'nid',
),
),
);
return $tables;
}
function mp3pig_views_arguments() {
$arguments = array(
'artist' => array('name' => t('Artist Name'), 'handler' => 'mp3pig_handler_arg_artist'),
);
return $arguments;
}
function mp3pig_handler_arg_artist($op, &$query, $argtype, $arg = '') {
switch ($op) {
case 'fields' :
//$query->add_table('aggregator2_audio', true);
$query->add_field('artist', 'aggregator2_audio');
$fieldinfo['field'] = 'aggregator2_audio.artist';
return $fieldinfo;
break;
case 'filter' :
$query->add_where("aggregator2_audio.artist LIKE '%%$arg%%'");
break;
case 'link' :
return l($query->name, "views/$arg/$query->artist");
case 'title':
return $query;
}
}
Comments
Comment #1
merlinofchaos commentedYour 'filter' case needs to do a $query->ensure_table() -- the add_where doesn't have any table info.
also, your embedded variables in the query string are dangerously unfiltered. I recommend %s substitution or running them through db_escape_string first, your pick. (Early views didn't support %s substitution unfortunately, so a lot of old examples didn't).
I recommend you grab a current views module and look at an existing argument for example. Many things have changed some and you'll do well to try to update your code to match.
Comment #2
RobRoy commentedCool, thanks. I've got the artist name working. Now I'm working on getting all the aggregator2_audio records for a specific agg2 feed id. The agg2_audio records are tied to the agg2_item records which have a fid in them.
I need help laying out the the tables structure.
Here is what I have so far:
Comment #3
RobRoy commentedP.S. I haven't gone through filtering the args, but it's on the TODO so don't worry about that.
Comment #4
RobRoy commentedHere is a general example of what I would do directly:
I have my module table aggregator2_audio which stores mp3 info
and ties to the following fields:
Then each agg2 item is tied to a agg2 feed:
So I want to find all aggregator2_audio records for a specific feed.
Something like this:
Obviously, we could remove the join to the agg2_feed table, but I thought that might help illustrate my point. Really, it would be this:
Comment #5
RobRoy commentedStill getting this when going to audio_by_feed/4936
Here is the relevant section of the code:
Comment #6
RobRoy commentedThis is the MySQL error: Unknown table 'aggregator2_feed' in where clause query: SELECT node.nid FROM drupal_node node WHERE (node.status = '1') AND (aggregator2_feed.nid = 4936) ORDER BY node.created DESC LIMIT 0, 36
Comment #7
RobRoy commented@merlin I got it working. I had some test data in the db that seemed to cause the error. Thanks for all your help. Here is the working views code.
Comment #8
(not verified) commented