Weird relationship update inconsistency with booted()

# regular property updates

$criteriaId = $data['criteria_id'];
$this->property->withoutTimestamps(function () use ($criteriaId) {
$this->property->update(['criteria_id' => $criteriaId]);
});

# using the following for bulk updates

$records->each(function ($property) use ($data) {
// Update the property without touching the timestamps
$property->withoutTimestamps(function () use ($property, $data) {
$property->update(['criteria_id' => $data['criteria_id']]);
});
});

# Property model, booted() method

static::updated(function ($property) {

if ($property->wasChanged('criteria_id')) {

# always shows correct criteria id
ray($property->criteria_id)->orange()->label('property criteria id');
# only shows related criteria when single property is updated, but null when bulk
ray($property->criteria?->name)->orange()->label('criteria name');
}
});
# regular property updates

$criteriaId = $data['criteria_id'];
$this->property->withoutTimestamps(function () use ($criteriaId) {
$this->property->update(['criteria_id' => $criteriaId]);
});

# using the following for bulk updates

$records->each(function ($property) use ($data) {
// Update the property without touching the timestamps
$property->withoutTimestamps(function () use ($property, $data) {
$property->update(['criteria_id' => $data['criteria_id']]);
});
});

# Property model, booted() method

static::updated(function ($property) {

if ($property->wasChanged('criteria_id')) {

# always shows correct criteria id
ray($property->criteria_id)->orange()->label('property criteria id');
# only shows related criteria when single property is updated, but null when bulk
ray($property->criteria?->name)->orange()->label('criteria name');
}
});
1 Reply
Mark Chaney
Mark ChaneyOP16mo ago
All the notes are in the code. I just dont get it. Im using the boot() method for some spatie activity logging, just removed that to keep example simple. i know this isnt completely specific to filament other that its happening during a bulk action on a table, hopefully someone has some ideas. The key issue/part is the following in the boot() method of the model
# only shows related criteria when single property is updated, but null when bulk
ray($property->criteria?->name)->orange()->label('criteria name');
# only shows related criteria when single property is updated, but null when bulk
ray($property->criteria?->name)->orange()->label('criteria name');
Ah mass updates don’t retrieve models Will have to do a foreach or something actually, the issue was that i needed to do $property->load('criteria'); within the boot method. Otherwise the relationship was always outdated
Want results from more Discord servers?
Add your server