1
中添加燈具並進行了一些研究後,我沒有找到任何適當的答案來解決這個問題。在Cakephp 3.x
我開始爲我的CakePHP(3.x)應用程序編寫測試,我在想如何添加燈具及其關聯?換句話說,我們如何將燈具鏈接到另一個燈具,而無需直接在燈具內寫入主鍵和外鍵。
即
我有一個用戶表和一個UserProfiles表。 用戶通過user_id列擁有一個UserProfile。這是我的用戶夾具。
namespace App\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
class UsersFixture extends TestFixture
{
public $import = ['table' => 'users'];
public $records = [
[
'username' => '[email protected]',
'primary_role' => 1
'is_active' => 1,
]
];
}
這是我的用戶配置夾具
namespace App\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
class UserProfilesFixture extends TestFixture
{
public $import = ['table' => 'user_profiles'];
public $records = [
[
'first_name' => 'Mark',
'last_name' => 'Yellowknife',
]
];
}
如何我都記錄聯繫在一起?也就是說,我如何告訴用戶配置文件記錄添加其user_id以鏈接到用戶記錄?
必須用夾具來做到這一點,而無需手動編寫密鑰。
謝謝你們!