I have a query, with a date field, let's say it is aliased as enabled. And joined table with field enabled_for_website. In my query alter, I want to substitute global enabled with date specific to website user is viewing (domain access, but it doesn't really matter here).
I tried simplistic approach:
function MYMODULE_query_MYTAG_alter($products_query) {
$products_query->join('website_has_product', 'wp', 'p.idProduct = wp.idProduct');
$products_query->join('website', 'w', 'wp.idWebsite = w.idWebsite');
global $user;
if ($user->uid == 1) {
$products_query->addField('wp', 'website_enabled', 'enabled');
}
$products_query->condition('w.WebsiteName', /*where are we */, '=');
}
I'm getting expected error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'enabled' in order clause is ambiguous
Is there a way to remove other column? SelectQuery::$fields
is protected, and I see no method to remove / substitute fields in it. I would prefer to avoid extending any classes.