Views: 281
Last Modified: 21.03.2022

In addition to GetList there are several methods allowing to get specific data in shorter format:

  • getById($id) - fetches data using the primary key;
  • getByPrimary($primary, array $parameters) - gets data via primary key using additional parameters;

    Note: both methods can pass id either as integer or by directly specified this element as key, by passing an array. You need to use an array if you have several primary fields. When you pass a non-primary key element in the array, it will be an error.

    BookTable::getById(1);
    BookTable::getByPrimary(array('ID' => 1));
    
    // such calls will be similar to the next call of getList:
    BookTable::getList(array(
    	'filter' => array('=ID' => 1)
    ));
  • getRowById($id) - fetches by primary key, but returns an array with data;
    $row = BookTable::getRowById($id);
    
    // similar result can be retrieved as follows:
    $result = BookTable::getById($id);
    $row = $result->fetch();
    
    // or as follows
    $result = BookTable::getList(array(
    	'filter' => array('=ID' => $id)
    ));
    
    $row = $result->fetch();
  • getRow(array $parameters) - fetches not using the primary key, but some other parameters. Returns only a single record.
    $row = BookTable::getRow(array(
    	'filter' => array('%=TITLE' => 'Patterns%'),
    	'order' => array('ID')
    ));
    
    // similar result can be retrieved as follows:
    $result = BookTable::getList(array(
    	'filter' => array('%=TITLE' => 'Patterns%'),
    	'order' => array('ID')
    	'limit' => 1
    ));
    
    $row = $result->fetch();



Courses developed by Bitrix24