500 Error when pointing to the same data object #61
-
In one of our projects we have a WorkerData, inside that WorkerData we Lazy the managers of a worker, managers is a hasManyThrough() from a join table which gives the Worker model again, the problem is, when validating the data (PUT/POST), it throws a 500 error Example: <?php
class WorkerData extends Data
{
public function __construct(
public string $first_name,
public string $last_name,
#[DataCollectionOf(WorkerData::class)]
public DataCollection | Lazy $managers,
) {}
public static function fromModel(Worker $worker): self
{
return new self(
managers: Lazy::whenLoaded('managers', $worker, fn () => WorkerData::collection($worker->managers)),
);
}
... Also tested with an hasOne() relation and the same issue happens, for example if the worker only had 1 manager: <?php
class WorkerData extends Data
{
public function __construct(
public string $first_name,
public string $last_name,
public WorkerData | Lazy $manager,
) {}
public static function fromModel(Worker $worker): self
{
return new self(
manager: Lazy::whenLoaded('manager', $worker, fn () => WorkerData::fromModel($worker->manager)),
);
}
... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @mazzv1, This is because the package will automatically try to deduce validation rules for the object. Since the You can fix this by setting the rules manually for the Be sure to do this on version 1.3.0, because on previous versions the memory bug would still occur. |
Beta Was this translation helpful? Give feedback.
Hi @mazzv1,
This is because the package will automatically try to deduce validation rules for the object. Since the
WorkerData
keeps getting nested, validation rules are also getting nested which causes an infinite loop.You can fix this by setting the rules manually for the
manager
property using therules
method.Be sure to do this on version 1.3.0, because on previous versions the memory bug would still occur.