You are here

public function DataTable::link in Data 7

Same name and namespace in other branches
  1. 6 includes/DataTable.inc \DataTable::link()

Link this table to another table. Linking a table to another one is to define how data in these tables should be joined to each other.

There can be more than one link to the left of a table. However, for views integration, only the first join created will be used.

@todo: Get rid of link() language, use setJoin()/removeJoin() instead.

File

includes/DataTable.inc, line 550
Contains class definition for DataTable.

Class

DataTable
Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.

Code

public function link($left_table, $left_field, $field = NULL, $inner_join = TRUE) {
  if ($field == NULL) {
    $field = $left_table;
  }

  // Remove previous join being overwritten.
  foreach ($this->meta['join'] as $joined_table_name => $joined_table_data) {
    if ($joined_table_data['field'] == $field) {
      unset($this->meta['join'][$joined_table_name]);
    }
  }
  $this->meta['join'][$left_table] = array(
    'left_field' => $left_field,
    'field' => $field,
    'inner_join' => $inner_join,
  );
  $this
    ->update(array(
    'meta' => $this->meta,
  ));
}