Skip to content

Fixed change sets of array updates #246

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

Merged
merged 2 commits into from
Feb 24, 2012
Merged

Conversation

tecbot
Copy link

@tecbot tecbot commented Feb 1, 2012

No description provided.

@@ -653,6 +653,8 @@ public function computeChangeSet(ClassMetadata $class, $document)
}
} else if (is_object($orgValue) && $orgValue !== $actualValue) {
$changeSet[$propName] = array($orgValue, $actualValue);
} else if (is_array($orgValue) && is_array($actualValue) && ($diff = array_diff($actualValue, $orgValue))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best possible check we can do here? Are their any other situations we need to account for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can check with !==.
The problem is if i have a array with 'foo' => 'bar' and i will change this to 'foo' => true the != operator doesn't work.

@jwage
Copy link
Member

jwage commented Feb 4, 2012

Duplicate of #209. The solution there looks more complex but I am not sure it is needed.

@tecbot
Copy link
Author

tecbot commented Feb 5, 2012

i think we should support better array updates, because in mongo we can update one single field in an array, but currently if i use the type hash and i change something the complete array will be updated but it is not useful. What do you think @jwage?

@jwage
Copy link
Member

jwage commented Feb 5, 2012

@tecbot that is what we have @EmbedMany for. PersistentCollection wraps around the array and tracks what is actually being changed. With just a plain old PHP array we have no introspection in to what has actually changed in the array. We can make the array diff or whatever we use more intelligent but I don't think it can ever be perfect.

@tecbot
Copy link
Author

tecbot commented Feb 6, 2012

@jwage yes i now, but if i want to store only a simple string in an array then i need to create a class like "StringEmbeddedDocument" and configure mappings, IMO its a overhead. I think we should support a more intelligent array update but not recursive.

@jwage
Copy link
Member

jwage commented Feb 6, 2012

We can add support for it, but it should be optional. The default should be a basic array with no heavy comparison because the overhead of doing the complex array comparison will also have significant overhead. I'd be curious to see benchmarks and have it compared to the same thing as an EmbedMany.

@tecbot
Copy link
Author

tecbot commented Feb 24, 2012

@jwage so what is the state of this pull request? can we merge this until we have found a better solution?

@jwage
Copy link
Member

jwage commented Feb 24, 2012

Sure we can merge and revise.

jwage added a commit that referenced this pull request Feb 24, 2012
Fixed change sets of array updates
@jwage jwage merged commit 57e7b2d into doctrine:master Feb 24, 2012
@jwage
Copy link
Member

jwage commented Feb 24, 2012

This commit broke the full test suite :(

@jwage
Copy link
Member

jwage commented Feb 24, 2012

ping @tecbot can you run the full test suite with the change?

@tecbot
Copy link
Author

tecbot commented Feb 24, 2012

...............................................................  63 / 427 ( 14%)
............................................................... 126 / 427 ( 29%)
............................................................... 189 / 427 ( 44%)
............................................................... 252 / 427 ( 59%)
............................................................... 315 / 427 ( 73%)
............................................................... 378 / 427 ( 88%)
.................................................

Time: 18 seconds, Memory: 181.50Mb

OK (427 tests, 1452 assertions)

all ok on my pc :).

@jwage
Copy link
Member

jwage commented Feb 24, 2012

It is failing for PHP 5.4 http://travis-ci.org/#!/doctrine/mongodb-odm/jobs/737202

@tecbot
Copy link
Author

tecbot commented Feb 24, 2012

hmm this is very weird... Array to string conversion ?? wtf

@tecbot
Copy link
Author

tecbot commented Feb 24, 2012

i have found that php 5.4 shows a notice now if you want to cast an array to string, so array_diff dosn't work for arrays in 5.4 if the values are an array, because he cast all entries to strings.

@jwage
Copy link
Member

jwage commented Feb 24, 2012

I see, we need to come up with a more robust solution than array_diff. I don't know what exactly it is, but I know that array_diff won't work.

@jwage
Copy link
Member

jwage commented Mar 2, 2012

I am going to revert this change until we have a better solution because the ODM is broken with php 5.4 as of right now. Unless you can send a PR to fix it today?

@geraldcroes
Copy link
Contributor

That's for PHP 5.4 that I did not use array_diff in #209, implementing a "dirty check".

@jwage
Copy link
Member

jwage commented Mar 2, 2012

@geraldcroes would you mind updating your PR and I will merge it?

@geraldcroes
Copy link
Contributor

@jwage What do you wan't me to update in the PR ? (already fixed standards & stuff as requested)

@lhecker lhecker deleted the array-changeset branch May 18, 2019 17:47
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

Successfully merging this pull request may close these issues.

3 participants