<?
namespace UserRating\MyTables;
use Bitrix\Main\Entity;
class IRresultsTable extends Entity\DataManager
{
public static function getTableName()
{
return 'i_results';
}
public static function getMap()
{
return array(
new Entity\IntegerField('ID' , array(
'primary' => true,
'autocomplete' => true
)),
new Entity\StringField('USER_ID' , array( // ссылка на поле другой таблицы
'data_type' => 'Bitrix\Main\UserTable',
'reference' => array('=this.USER_ID' => 'ref.NAME')
)),
new Entity\StringField('DISCIPLINE_ID'),
new Entity\StringField('SCORE')
);
}
}
?>
Александр Медведев написал: Из одной таблицы ты читаешь данные и в результате этой операции в другой таблице должно что-то измениться. Я правильно понял?
Захотел сделать как там написано, связать поле из своей таблицы с полем таблицы битрикса, скрин https://yadi.sk/i/WudxxMW7l7VueQ , но ничего не получилось - не работает.
<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
use \Bitrix\Main\Application; // подключение точки входа https://dev.1c-bitrix.ru/api_d7/bitrix/main/application/index.php
use Bitrix\Main\Entity\Base;
//подключаю таблицы
require ('tables/i_disciplines.php');
require ('tables/i_results.php');
//проверка таблицы на существование
if( !Application::getConnection(\UserRating\MyTables\IDisciplinesTable::getConnectionName()) -> isTableExists(
Base::getInstance('\UserRating\MyTables\IDisciplinesTable') -> getDBTableName()) )
{
$base = Base::getInstance('\UserRating\MyTables\IDisciplinesTable');
$base->createDbTable();
}
//проверка таблицы на существование
if( !Application::getConnection(\UserRating\MyTables\IRresultsTable::getConnectionName()) -> isTableExists(
Base::getInstance('\UserRating\MyTables\IRresultsTable') -> getDBTableName()) )
{
//создание таблицы
$base = Base::getInstance('\UserRating\MyTables\IRresultsTable');
$base->createDbTable();
}
Описание таблицы
<?
Код
namespace UserRating\MyTables; // должен быть первым
use Bitrix\Main\Entity;
class IRresultsTable extends Entity\DataManager
{
public static function getTableName()
{
return 'i_results';
}
public static function getMap()
{
return array(
new Entity\IntegerField('ID' , array(
'primary' => true,
'autocomplete' => true
)),
new Entity\StringField('USER_ID' , array( // ссылка на поле другой таблицы
'data_type' => 'Bitrix\Main\UserTable',
'reference' => array('=this.USER_ID' => 'ref.NAME')
)),
new Entity\StringField('DISCIPLINE_ID'),
new Entity\StringField('SCORE')
);
}
}
?>
new Entity\StringField('USER_ID' , array( // ссылка на поле другой таблицы
'data_type' => 'Bitrix\Main\UserTable',
'reference' => array('=this.USER_ID' => 'ref.NAME')
)),
Это не ссылка, сделай так
Код
use Bitrix\Main\ORM\Fields\IntegerField;
use Bitrix\Main\ORM\Fields\Relations\Reference;
use Bitrix\Main\ORM\Query\Join;
use Bitrix\Main\UserTable;
...
new IntegerField( 'user_id' ),
new Reference( 'user', UserTable::class, Join::on( 'this.user_id', 'ref.ID' ) )
new Entity\StringField('USER_ID' , array( // ссылка на поле другой таблицы
'data_type' => 'Bitrix\Main\UserTable',
'reference' => array('=this.USER_ID' => 'ref.NAME')
)),
Это не ссылка, сделай так
Код
use Bitrix\Main\ORM\Fields\IntegerField;
use Bitrix\Main\ORM\Fields\Relations\Reference;
use Bitrix\Main\ORM\Query\Join;
use Bitrix\Main\UserTable;
...
new IntegerField( 'user_id' ),
new Reference( 'user', UserTable::class, Join::on( 'this.user_id', 'ref.ID' ) )