Problem with dropdown in CRUD


#1

Hey, I can’t figure out, how to do this with ATK:

I have the following data structure:
User [id,name]
Car[id,name,user_id]
Key[id,name,user_id]

So every User can have cars and keys. Everything is working fine so far. Now I want to assign keys to users.

So I change Key to Key[id,name,user_id,car_id]

This looks in code like:

class Key extends \atk4\data\Model
  {
      public $table = 'key';
      function init()
      {
          parent::init();
          $this->addFields([
              'name'
          ]);
          $this->hasOne('user_id', new User());
          $this->hasOne('car_id', new Car())->addField('CarName', 'name');;
      }
  }

And my page for displaying looks like this:

<?php
require 'lib.php';
$app = new MyApp();
$userid = $_SESSION['user_id'];
if (isset($clientid)) {
    $app->user = new User($app->db);
    $app->client->tryLoad($userid);
    $crud=$app->layout->add([
'CRUD',
    'fieldsUpdate' => ['name','car_id'],
	'fieldsCreate' => ['name','car_id'],
	'fieldsDefault'=>['name']
]);
    $crud->setModel($app->client->ref('Key'));
	$crud->addQuickSearch();
}

Everything works quite well, the only problem is, that in the Dropdown for the cars ALL cars for all users are displayed and not only the ones for my current user.

How can I restrict the values in the dropdown field?