Hello, I'm trying to alter a view using foo_views_query_alter, my problem is that the table is not int the global table array. In the Views doc it's said in views_query::add_table that $table The name of the table to add. It needs to exist in the global table array. But I don't know how to add my table to that variable (adding it like this doesn't work $query->tables[] = 'mytable';).
After that I try this:

	$query->add_table('mytable', NULL, NULL, 'mt');
	$query->add_where('0', 'mt.files = 1');

Any ideas? Thank you.

Comments

nevets’s picture

If you have views and advanced help installed, the advanced help for views includes developer notes on how to defined tables and their fields so views knows about them.

PawelR’s picture

you can try:

$query->tables['node'][] = 'mytable';
$query->table_queue[] = 'mytable';

However I would recommend to examine (print_r or using debugger) query object first.

There is also more 'dirty' way of amending a query in a view.
You can implement hook_views_pre_execute where query is already build and you can alter query string.

You can play with query and count-query variables for example:

$view->build_info['query'] = ....;
$view->build_info['count_query']) = ...;
bullakio@drupal.org’s picture

Thanks for your help. Unfortunatly it doesn't work... I think I must do a lot of work for so a simple think... it's a petty. But anyway, thanks a lot for your answer.