i have the following models
<?php
namespace App\Models\Masters\System;
class UserActivationCode extends \Illuminate\Database\Eloquent\Model
{
public $table = "user_activation_codes";
}
<?php
namespace App\Models;
use App\Models\Model;
use Modules\Requests\Models\EmploymentLeaveType;
use App\Models\Masters\System\UserActivationCode;
class EmployeeEmployment extends \Illuminate\Database\Eloquent\Model {
public $table = "employee_employments";
public function employeeProfileScore() {
return $this->hasOne('\App\Models\EmployeeProfileScore', 'employee_id', 'employee_id');
}
public function test() {
return $this->hasMany(UserActivationCode::class, 'employment_id', 'id');
}
}
in tinker when i run the following commands
$emp = \App\Models\EmployeeEmployment::with('test')->whereIn('id', ["4228e839-5ce3-4798-acfd-68958fed3b82"])->first();
$emp->test;
the result is empty array
but when i run without with it returns data
$emp = \App\Models\EmployeeEmployment::whereIn('id', ["4228e839-5ce3-4798-acfd-68958fed3b82"])->first();
$emp->test;
i removed everything from model converted it into base state in query i have the following query running i cant understand why employment_id in 0
[2024-01-24T11:08:27.192268+00:00] Query.INFO: select * from `employee_employments` where `id` in (?) {"Bindings":["4228e839-5ce3-4798-acfd-68958fed3b82"],"Time":2.65,"Origin":[]} []
[2024-01-24T11:08:27.197588+00:00] Query.INFO: select * from user_activation_codes where user_activation_codes.employment_id in (0) {"Bindings":[],"Time":1.29,"Origin":[]} []
Check how your test relationship is being loaded. Is there perhaps a mismatch between the foreign keys and what is set in your database? Make sure that employment_id and id in the user_activation_codes table are of the same type in your database (both UUID if you are using UUIDs).