atk4 / data

Data Access PHP Framework for SQL & high-latency databases

Home Page:https://atk4-data.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hasMany referencing a table in another db generates ciritcal error from lack of fallback field

samsouthardjr opened this issue · comments

With two classes:

class Parent extends Model
{
   public $table = 'db1.parent';

   protected function init(): void
   {
      parent::init();
      $this->addField('name');
      $this->hasMany('children', ['model' => [Child::class]]);
    }
}

class Child extends Model
{
   public $table = 'db2.child';

   protected function init(): void
   {
      parent::init();
      $this->addField('name');
      $this->hasOne('parent_id', ['model' => [Parent::class]]);
   }
}

With those classes, the code:

$p = new Parent($db);
$c = $p->ref('children');

will generate an exception "Atk4\Data\Exception: Their model does not contain fallback field" as it will attempt to reference a their_fallback_field of 'db1.parent_id' (it should be simply 'parent_id').

Adding "their_field' => 'parent_id' to the hasMany definition resolves this, but shouldn't be necessary