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

Immutable Validator does not support DbRefs, or objects in general #92

Open
pmaselkowski opened this issue May 5, 2020 · 0 comments
Open

Comments

@pmaselkowski
Copy link
Member

Scenario:

  1. I create model with DbRef field
  2. I set field value to some referenced model
  3. I save
  4. I load model again

Current:

  1. Validator prevents saving stating that field has changed. The reason is that comparison is done with ===, however for objects it should be somewhat different. And for DbRefs should only compare if it is same document

Expected:

  1. Because DbRef points to same object, it should allow saving even if object is different

Offending code in Maslosoft\Mangan\Validators\BuiltIn\ImmutableValidator:

...
                // Not stored in DB
		if (empty($found->$against))
		{
			return true;
		}

		// Stored in DB, but value is same
		if ($found->$attribute === $model->$attribute)  // <<< HERE
		{
			return true;
		}

		$label = ManganMeta::create($model)->field($attribute)->label;
		$this->addError('msgImmutable', ['{attribute}' => $label, '{value}' => $value]);
		return false;
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant