title: Nette Database: No reference found for Join query
body: <p>How do you create a query in the renderDefault function with JOINS? I have been looking at nette docs for a while and I can't seem to find my answer. That's why I wanted to ask someone experienced. Who could already know the answer?</p>
  <p>** Let's say you got this query**</p>
  <pre><code>SELECT a.id, a.firstname, a.lastname, b.name FROM racers a JOIN types b ON b.id = a.type
  </code></pre>
  <p><strong>And you would like to create it like this:</strong></p>
  <pre><code>public function renderDefault(): void
  {
  $this-&gt;template-&gt;racers = $this-&gt;database-&gt;table('racers');
  }
  </code></pre>
  <p><strong>One of my ideas was to do something like this</strong></p>
  <pre><code>public function renderDefault(): void
  {
  $this-&gt;template-&gt;racers = $this-&gt;database-&gt;table('racers')
  -&gt;select('racers.id, racers.firstname, racers.lastname, types.name')
  -&gt;joinWhere('types', 'types.id = racers.type');
  }
  </code></pre>
  <p>for some reason &quot;my&quot; query seems to work until I need to use it in foreach loop in a latte.
  and that is why I am wondering what is a better way to do this.</p>
  <pre><code>{foreach $racers as $racer}
  &lt;tr&gt;
    &lt;th scope=&quot;row&quot;&gt;{$racer-&gt;id}&lt;/th&gt;
    &lt;td&gt;{$racer-&gt;firstname}&lt;/td&gt;
    &lt;td&gt;{$racer-&gt;lastname}&lt;/td&gt;
    &lt;td&gt;{$racer-&gt;name}&lt;/td&gt;
  &lt;/tr&gt;
  {/foreach}
  </code></pre>
  <p><strong>Error:</strong></p>
  <pre><code>Nette\InvalidArgumentException 
  No reference found for $racers-&gt;types.
  </code></pre>