Multiple queries appear in tp5 one-to-many association

tp5 one-to-many associations, the code logically queries the number of associations only once, but debugging shows that there are two database queries.

is just Student- > klass- > all (), which makes an associative query, but actually queries the database twice.

{volist name="Student->Klass->all()" id="klass"}
<option value="{$klass->id}" {eq name="klass->id" value="$Student->klass_id"}selected="selected"{/eq}>{$klass->name}</option>
{/volist}

how can I avoid multiple database queries?

May.27,2022

should be the first query problem of ORM. You can try associative preloading

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35212-4d609.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35212-4d609.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?