Hello, I'm here because I can't figure out how to manage this. It's more like an improvement on application, that is working as planed. But it's performing more than desired number of SQL queries.
Thats why I want to use join to reduce the number of queries. Supposing that I have the code:
Assuming that I have a well configured Robot Model, with all hasMany and belongsTo defined...
On controller listAction(), I have the code to fetch all the Robots:
$robotsQuery = Robots::query();
$robotsQuery->join("RobotBrand"); //The related brand of the robot, oneToMany 1..N
$this->view->allRobots = $robotsQuery->execute(); // Passing all the robots to the view
And then In the view, I list the robots:
<ul>
{% for robot in allRobots %}
<li>{{ robot.name }} - {{ robot.RobotBrand.name }}</li>
{% endfor %}
</ul>
This code worked well, but when I took a look at the log of database executed queries, I notice that for each robot, another Query to select the brand was executed.
What am I doing wrong. The desired effect would be to bring together with each robot, at least the one to many related data.
With that I would be able to execute a single query to bring all the robots with brand data included.
Thankyou !