Skip to content

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

@samsouthardjr

Description

@samsouthardjr

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions