Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update BelongsTo relation makes from old_values ID Integer insead of String type #763

Open
NoahNxT opened this issue Jan 29, 2023 · 1 comment

Comments

@NoahNxT
Copy link

NoahNxT commented Jan 29, 2023

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 9.48.0
Package version 13.0
PHP version 8.1

Actual Behaviour

When updatinga BelongsTo relation, the old_values id is parsed to an Int instead of a string.
This makes searching with whereJsonContains unpossible because you'll have to always check for both types

image

This is how I need to check in the audits table for a presence value now:

Audit::whereJsonContains('old_values', ['protocol_id' => $this->id])
            ->orWhereJsonContains('old_values', ['protocol_id' => (string)$this->id])
            ->orWhereJsonContains('new_values', ['protocol_id' => $this->id])
            ->exists();

Expected Behaviour

When updating a BelongsTo relation, the old_value of the id should be parsed to a string like any other action.

**old_values

"model_id":"9",

Steps to Reproduce

  1. Make a belongsTo Many relation
  2. Attach the BelongsTo
  3. Update the BelongsTo
  4. Now you can see the different type in the old_values column

Possible Solutions

Hard cast to (Int)

@parallels999
Copy link

Hi, feel free to make a PR to fix that, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants