Hi there, I’m trying to insert test data into the database, but when I try to insert a value with a foreign key brand me an error: Exception ‘yii \ base \ UnknownPropertyException’ with message ‘Getting unknown property: test \ unit \ fixtures \ EmpresasFixture :: class’
I can’t pass values from one table to another, deputy codes that I am using.
This is the code of User and work well when i run
yii fixture/load User
tests/unit/fixtures/UserFixture.php
<?php
namespace tests\unit\fixtures;
use yii\test\ActiveFixture;
class UserFixture extends ActiveFixture
{
public $modelClass = 'common\models\User';
}
tests/unit/fixtures/user.php
<?php
return [
'user1' => [
'username' => 'lmayeart',
'auth_key' => 'K3nF70it7tzNsHddEiq0BZ0i-OU8S3xV',
'email' => 'testing2@gmail.com',
'status' => '10',
],
];
My problem is when i try to insert information in Empresas table using “user1” as foreign key it give problem because i can’t use the User information as property:
tests/unit/fixtures/EmpresasFixture.php
<?php
namespace tests\unit\fixtures;
use yii\test\ActiveFixture;
use tests\unit\fixtures\UserFixture;
class EmpresasFixture extends ActiveFixture
{
public $modelClass = 'frontend\models\Empresas';
public $depends = ['tests\unit\fixtures\UserFixture'];
public function fixtures()
{
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => '@app/tests/unit/fixtures/data/user.php',
],
];
}
}
tests/unit/fixtures/data/empresas.php
<?php
return [
'empresa1' => [
'user_id' => $this->class['user1'],
'cuenta' => 'cuenta 1',
'status' => 'activo',
],
];
And when i run
yii fixture/load User
give me this error: “Exception ‘yii\base\UnknownPropertyException’ with message ‘Getting unknown property: tests\unit\fixtures\EmpresasFixture::profiles’”
Hope you can help me
Warm Regards