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

.
Menu