Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Count cache support nullable #118

Merged
merged 2 commits into from
May 16, 2024
Merged

Count cache support nullable #118

merged 2 commits into from
May 16, 2024

Conversation

fmarquesto
Copy link
Contributor

When we use CountedBy on a nullable field and we set this to null:

...
$table->integer('user_id')->nullable();
...

$post->userId = null;

We receive an unexpected error:
TypeError : Eloquence\Behaviours\CacheConfig::relatedModel(): Return value must be of type Illuminate\Database\Eloquent\Model, null returned

With this PR I've added a validation to avoid retrieving the model on the update method if the foreignKey value is null.

@kirkbushell kirkbushell merged commit d4734d7 into kirkbushell:master May 16, 2024
4 checks passed
@fmarquesto fmarquesto deleted the count-cache-support-nullable branch May 16, 2024 01:20
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants