Closed Restingo closed 6 months ago
Hi @Restingo, could you provide a repository with sample code that reproduces this issue?
I have the same problem, this happens when you have a hasMany() relationship and the local key is null
This is also happening to me. I've been stuck on 0.12.3
same problem in the latest version which is 0.13
@mikebronner is there any plan to fix this, or maybe a workaround?
i also tries to install a lower version (0.12.2) but it has problem with latest version of laravel.
I'm having the same issue after upgrading to Laravel 10.
Looks like #432 is related.
@Ham3D @wolfpack4417 are you able to reproduce and paste the code or snippet here? I fixed it somehow in my env but don't know how. If you can give me the reproducible code I'll create a fix. Thank you.
@Restingo It's been a while since we had this issue and what I can remember if you have a setup like the snippet below and local_id in classB is null in the database you get this error.
class classA extends Model {
protected $fillable = [
'foreign_id',
];
}
class classB extends Model {
protected $fillable = [
'local_id',
];
public function classA(): HasMany
{
return $this->hasMany(classA::class, 'foreign_id', 'local_id');
}
}
(I wrote this from head so you might need to tweek it)
@Restingo I'm getting this error when trying to delete an entity that also has soft cascading deletes via this package : askedio/laravel-soft-cascade
This is the code:
`class FuelCard extends BaseModel { protected $table = 'fuel_cards'; protected $fillable = ['account_id', 'fcp', 'driver_id', 'vehicle_id', 'unique_identifier', 'fuel_type', 'driver_resource_id'];
protected $softCascade = ['fuelTransactions'];
public static function boot() {
parent::boot();
static::deleting(function($fuel_card) {
$fuel_card->fuelTransactions()->delete();
});
}
public function account()
{
return $this->belongsTo(Account::class);
}
public function fuelTransactions()
{
return $this->hasMany(FuelTransaction::class);
}
} `
And it fails here:
$fuel_card->fuelTransactions()->delete();
Let me know if you need any more information from me, and thanks for helping with this!
@wolfpack4417 would it be possible to push a small repo with the needed code in it to reproduce? Thx.
or submit a PR with a failing test, either would be great
@mikebronner I am facing this issue now with a nullable one-to-many relationship Package Version: 0.13.4 Laravel: 10.8 PHP: 8.2
I was able to get around this issue by adding a null cast type and null return type to vendor/genealabs/laravel-model-caching/src/CacheKey.php processEnum() method. Could someone be able to have a look and make sure this doesn't cause any negative effects. I tried creating a PR but i'm a PR Rookie and couldn't figure out how to push it... i kept getting permission errors.
private function processEnum(\BackedEnum|\UnitEnum|Expression|string|null $value): string|null
{
if ($value instanceof \BackedEnum) {
return $value->value;
} elseif ($value instanceof \UnitEnum) {
return $value->name;
} elseif ($value instanceof Expression) {
return $this->expressionToString($value);
}
return $value;
}
@peter-brennan thanks for submitting additional details. I will take a look at this.
I figured out how to create a PR hahaha, I made that change for you. #456
Nice, that helps a lot, thanks @peter-brennan !
Any news? I am facing the same issue and have been waiting for a fix.
How is the progress? I'm facing the same issue and have been waiting for a fix.
Reviewing the PR now ... hopefully I can get it merged this morning.
This should be fixed now. Thanks for your patience.
Thank you very much and wish you a Merry Christmas in advance.
@mikebronner My PHP version is 8.0 and I can only use version 0.12.5. I want to fix this problem in version 0.12.5, Can you create a branch based on tag 0.12.5? So can I create a pull request to merge into this branch and then have you create a 0.12.6 tag?
Hi @emptyrealm, I would recommend you create a fork for your use, downgrade PHP in your fork, then return to using the package once you are back on a supported PHP version. At this time I won't be adding back-support to older versions of PHP or Laravel.
However, once this package gets to version 1.0 (hopefully by or before Laravel 12), we will be maintaining LTS version support for Laravel, and Active/Security supported versions of PHP.
@mikebronner OK, I'll try it, thank you for your patience reply.
This Package is really useful, thank you.
Describe the bug Since the version
0.12.4
I get errorGeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given, called in ...\vendor\genealabs\laravel-model-caching\src\CacheKey.php on line 409
when querying a relationship on a new model that is currently empty.Eloquent Query
Stack Trace
Environment
Additional context Tried downgrading to
0.12.3
to test and with this version it works.