Created
July 16, 2018 13:46
-
-
Save anoriar/87373061ae43f24b0667d6adea76fd7c to your computer and use it in GitHub Desktop.
Сущности многие ко многим: Книги Авторы, сложный запрос: перечисление авторов каждой книги
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Orm; | |
use Bitrix\Main\Entity; | |
use Bitrix\Main\Type\Date; | |
class BookTable extends Entity\DataManager{ | |
public static function getTableName() | |
{ | |
return 'book'; | |
} | |
public static function getMap() | |
{ | |
return array( | |
new Entity\IntegerField('ID', array( | |
'primary' => true, | |
'autocomplete' => true | |
)), | |
new Entity\IntegerField('ISBN'), | |
new Entity\StringField('TITLE'), | |
new Entity\DateField('PUBLISH_DATE', [ | |
'default_value' => new Date | |
]) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$res = BookTable::getList(array( | |
'select' => array( | |
'TITLE', | |
'AUTHORS', | |
), | |
'group' => array('Orm\BookAuthor:BOOK.BOOK_ID'), | |
'runtime' => array( | |
new Entity\ExpressionField('AUTHORS', 'GROUP_CONCAT(%s SEPARATOR \', \' )', ["Orm\BookAuthor:BOOK.AUTHOR.NAME"]), | |
new Entity\ExpressionField('CNT', "COUNT(DISTINCT %s)", ["Orm\BookAuthor:BOOK.AUTHOR.NAME"]) | |
), | |
'filter' => array('>=CNT' => 2) | |
)); | |
while ($row = $res->fetch()) | |
{ | |
$rows[] = $row; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment