F
Filament16mo ago
Ander

hasone relations and belong to

I am trying to use 2 relations in a resource, the model is "employee", through this I am making the first relation to get to the "EmployeeAddress" table, the relationship is hasOne, data: 'employee_id','address_id', 'start_date', 'end_date', the second is to get to the "Address" table, the relationship is belongs to, data: 'street_1', 'street_2', 'city', 'state', 'postal code'. but when saving all the data it returns this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause'
update `employee_addresses` set `address_id` = 22783556 where `` = 22783541 and `` = 22783541
update `employee_addresses` set `address_id` = 22783556 where `` = 22783541 and `` = 22783541
but it is supposed that when the relation is there it returns the id, isn't it?
relationships:
model: Employee
public function employeeAddress()
{
return $this->hasOne('App\Models\Tenant\EmployeeAddress','employee_id');
}

model: EmployeeAddress
public function address()
{
return $this->belongsTo('App\Models\Tenant\Address', 'address_id');
}


Group::make()
->relationship('employeeAddress')
->schema([
Hidden::make('start_date')->default(now()->toDateString()),
Hidden::make('end_date')->default(now()->toDateString()),
Group::make()
->relationship('address')
->schema([
TextInput::make('street_1'),
TextInput::make('street_2'),
TextInput::make('city'),
TextInput::make('state'),
TextInput::make('zip'),
]),
]),
relationships:
model: Employee
public function employeeAddress()
{
return $this->hasOne('App\Models\Tenant\EmployeeAddress','employee_id');
}

model: EmployeeAddress
public function address()
{
return $this->belongsTo('App\Models\Tenant\Address', 'address_id');
}


Group::make()
->relationship('employeeAddress')
->schema([
Hidden::make('start_date')->default(now()->toDateString()),
Hidden::make('end_date')->default(now()->toDateString()),
Group::make()
->relationship('address')
->schema([
TextInput::make('street_1'),
TextInput::make('street_2'),
TextInput::make('city'),
TextInput::make('state'),
TextInput::make('zip'),
]),
]),
1 Reply
Ander
AnderOP16mo ago
the error was because in my migration I did not have the timestamps
Want results from more Discord servers?
Add your server