no reference found – following guide

kolaloka
Member | 69
+
0
-

Hi, I am following this guide: https://doc.nette.org/…ase/explorer
section “Filtering by another table value”

This is my presenter with DI context

<?php
declare(strict_types = 1);

namespace App\Presenters;

use Nette;
use Nette\Application\UI\Form;

final class SeatPresenter extends Nette\Application\UI\Presenter {

    /** @var Nette\Database\Context */
    private $database;

   public function __construct(Nette\Database\Context $database) {
        $this->database = $database;
    }
    public function createToday(){
        $today = date("Y/m/d");
        return $today;
    }

    public function renderDefault() {
        $today = $this->createToday();
        $seat = $this->database->table('bookevent');
        $seat->where('bookdate.date',$today);
        $this->template->seat = $seat;

    }


}

These are my tables, which follow the naming convention:

MariaDB [dashboard]> show tables;
+---------------------+
| Tables_in_dashboard |
+---------------------+
| bookdate            |
| bookdesk            |
| bookevent           |
| servers             |
| user                |
+---------------------+
5 rows in set (0.002 sec)

MariaDB [dashboard]> show columns from bookdate;
+---------+-------------------------------------------------+------+-----+---------+----------------+
| Field   | Type                                            | Null | Key | Default | Extra          |
+---------+-------------------------------------------------+------+-----+---------+----------------+
| id      | int(11)                                         | NO   | PRI | NULL    | auto_increment |
| date    | date                                            | NO   |     | NULL    |                |
| holiday | tinyint(4)                                      | YES  |     | 0       |                |
| dow     | enum('Mon','Tue','Wed','Thu','Fri','Sat','Sun') | NO   |     | NULL    |                |
+---------+-------------------------------------------------+------+-----+---------+----------------+
4 rows in set (0.002 sec)

MariaDB [dashboard]> show columns from bookdesk;
+--------+---------+------+-----+---------+----------------+
| Field  | Type    | Null | Key | Default | Extra          |
+--------+---------+------+-----+---------+----------------+
| id     | int(11) | NO   | PRI | NULL    | auto_increment |
| number | int(11) | NO   |     | NULL    |                |
+--------+---------+------+-----+---------+----------------+
2 rows in set (0.001 sec)

MariaDB [dashboard]> show columns from bookevent;
+-------------+---------+------+-----+---------+----------------+
| Field       | Type    | Null | Key | Default | Extra          |
+-------------+---------+------+-----+---------+----------------+
| id          | int(11) | NO   | PRI | NULL    | auto_increment |
| bookdate_id | int(11) | NO   |     | NULL    |                |
| bookdesk_id | int(11) | NO   |     | NULL    |                |
| user_id     | int(11) | NO   |     | NULL    |                |
+-------------+---------+------+-----+---------+----------------+
4 rows in set (0.001 sec)

But I get:

No reference found for $bookevent->bookdate.

from Tracy :-(

Help please
Kolaloka

nightfish
Member | 517
+
+1
-

kolaloka wrote:

No reference found for $bookevent->bookdate.

Does your bookevent table have foreign key to tables bookdate and bookdesk? If not, add them, clear cache and try again.

kolaloka
Member | 69
+
0
-

Nightfish, youre great! Thanks! That worked!

For anyone who comes here to check, this was the command:

MariaDB [dashboard]> alter table bookevent
    -> add constraint FK_BookdateBookevent
    -> foreign key (bookdate_id) references bookdate(id);
Query OK, 8 rows affected (0.019 sec)
Records: 8  Duplicates: 0  Warnings: 0