I've got two tables, table1
and table2
, connected via many-to-many.
So far there is no problem, but I would get a server-collapse for using the code below in productive usage.
Accessing the many-to-many-join generates far to much queries.
Is there some better way to access the data (without raw querys)?
Code:
<?php
$table1_entry = R::findAll('table1');
foreach($table1_entry as $table1)
{
echo $table1->id;
foreach($table1->sharedTable2 as $table2)
{
echo $table2->id;
}
}
?>
Redbean Query-Log:
string(34) "SELECT * FROM `table1` -- keep-cache"
[1] =>
string(71) "SELECT * FROM `table2_table1` WHERE ( `table1_id` IN ( ?) ) -- keep-cache"
[2] =>
string(61) "SELECT * FROM `table2` WHERE ( `id` IN ( 1) ) -- keep-cache"
[3] =>
string(71) "SELECT * FROM `table2_table1` WHERE ( `table1_id` IN ( ?) ) -- keep-cache"
[4] =>
string(61) "SELECT * FROM `table2` WHERE ( `id` IN ( 2) ) -- keep-cache"
[5] =>
string(71) "SELECT * FROM `table2_table1` WHERE ( `table1_id` IN ( ?) ) -- keep-cache"
[6] =>
string(61) "SELECT * FROM `table2` WHERE ( `id` IN ( 3) ) -- keep-cache"
[7] =>
string(71) "SELECT * FROM `table2_table1` WHERE ( `table1_id` IN ( ?) ) -- keep-cache"
[8] =>
string(61) "SELECT * FROM `table2` WHERE ( `id` IN ( 4) ) -- keep-cache"
[...]