I have in the model Finca.php
public function piscinas(){
return $this->hasMany(Piscina::class)->select('id' , 'finca_id', 'area' , 'name');
}
public function getPiscinasPlanificadasAttribute(){
return $this->hasMany(Piscina::class)
->leftJoin('planificaciones', 'planificaciones.piscina_id', '=', 'piscinas.id')
->select('piscinas.id' , 'piscinas.finca_id', 'piscinas.area' , 'piscinas.name' , 'planificaciones.created_at as planificacion_created_at' , 'planificaciones.precio_larva' , 'planificaciones.densidad' , 'planificaciones.id as planificacion_id')
->whereNotNull('planificaciones.piscina_id')
->whereNull('planificaciones.deleted_at')
->get();
}
public function getPiscinasSinPlanificarAttribute(){
return $this->hasMany(Piscina::class)
->leftJoin('planificaciones', 'planificaciones.piscina_id', '=', 'piscinas.id')
->select('piscinas.id' , 'piscinas.finca_id', 'piscinas.area' , 'piscinas.name')
->WhereNull('planificaciones.piscina_id')
->get();
}
And in the model Piscina.php
public function finca(){
return $this->belongsTo(Finca::class);
}
public function planificacion(){
return $this->belongsTo(Planificacion::class);
}
It works great, the problem is that when using softdelete, when you delete the planning of a pool, the record is left in the planning table, later if I want to add a new planning to the pool, the pools do not appear without planning, obviously because pool.id is no longer null, it exists in the "schedules" table but with the deleted field filled.
Is there any way to bring back the pools_ without planning?