Additional fields for my entity from another table in views I have table of my entity with structure:

=====================================
eid | myfield1 | myfield2 | myfield3
=====================================


And also an additional table with primary key being foreign key to my entity id:

==========================
eid | myfield4 | myfield5
==========================


I would like to expose values in my second table to view of fields, of my entity, but I don't want to join second table with first, every time, but only if I will use one of its fields.

I believe it should be doable with views_join class modifying a query at handler level, but is it possible on hook_views_data_alter() level?

Is it possible to do this transparently - so I wouldn't need to add any relationship to view (just like the field values are pulled from fields tables - yes, you can think a bit about it as about creating fields alternative ;) ) ?
Technically it's possible, using hook_views_query_alter(), you can adapt the view query to add or change conditions. So you could add a join with something like this:

function modulename_views_query_alter(&amp;$view, &amp;$query) {
  $join = new views_join();
  $join-&gt;table = 'mytable';
  $join-&gt;field = 'eid';
  $join-&gt;left_table = 'entity_table';
  $join-&gt;left_field = 'eid';
  $join-&gt;type = 'left';
  $query-&gt;add_relationship('relationship_name', $join, 'entity_table');
}


But a better approach would be to use hook_views_data() to expose your table to views, and then add the relevant fields when needed (with a relationship though), but in practical terms is no different than altering the query.