problem pri joinovani tabuliek
- Matej123
- Člen | 150
Mam tabulku partners a courses medzi ktorymi je vztah M:N, teda mam vytvorenu
dalsiu tabulku courses_partners, kde je len course_id a partner_id , ktore
tvoria spolu primary key a course_id jeforeign key do tabulky courses a
partner_id do partners.
V modeli CourseManager predavam takto data:
<?php
return $this->database->table('courses_partners');
?>
V presenteri:
<?php
$this->template->course = $this->courseManager->getAll();
?>
V sablone to vypisujem takto:
<?php
{foreach $courses as $course}
<tr>
<td>{$course->courses->title}</td>
<td>{$course->courses->description}</td>
<td>{$course->courses->time|date:'d.m.Y'}</td>
<td>{$course->courses->place}</td>
<td> účastníci - {$course->partners->firstName} </td>
<td>
<a n:href="Course:detail $course->course_id" class="btn btn-success">detail</a>
</td>
</tr>
{/foreach}
?>
na konci mi vypise chybu ze nepozna premenu courses v tomto riadku :
<?php
<td>{$course->courses->title}</td>
?>
- David Matějka
- Moderator | 6445
pri „to one“ smeru se klic odvozuje od nazvu sloupecku, ne od nazvu tabulky, viz https://doc.nette.org/…ase/explorer#…
takze $course->course->title
- Matej123
- Člen | 150
dakujem, pomohlo, mozem este jednu vec?
ten isty priklad len z where podmienkou, ako zavolat atribut z courses tabulky? priklad nizsie nefunguje
<?php
$this->database->table('courses_partners')->where('courses.time > ?', $currentDate);
?>
F.Vesely napsal(a):
Zkus
<td>{$course->course->title}</td>
Editoval Matej123 (16. 12. 2015 15:25)
- David Matějka
- Moderator | 6445
uplne stejny problem. koukni na muj prispevek vyse a na uvedeny odkaz.