Skip to content

Remove embedded documents complexity #782

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

Closed
wants to merge 14 commits into from

Conversation

jwage
Copy link
Member

@jwage jwage commented Jan 25, 2014

*/
private function computeAssociationChanges($parentDocument, $mapping, $value)
private function computeAssociationChanges($parentDocument, $assoc, $value)
Copy link
Member

Choose a reason for hiding this comment

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

Type-hint $assoc as array here?

@jmikola
Copy link
Member

jmikola commented Jun 6, 2014

@jwage: Is this still in progress?

@jwage
Copy link
Member Author

jwage commented Jun 6, 2014

@jmikola yes it is, I just haven't had time to continue working on it.

@jmikola jmikola added this to the 1.0.0-BETA12 milestone Jun 6, 2014
@jmikola jmikola added the task label Jun 6, 2014
@jmikola
Copy link
Member

jmikola commented Aug 28, 2014

@jmikola jmikola modified the milestones: 1.0.0-BETA12, 1.0.0-BETA13 Feb 24, 2015
@jwage jwage force-pushed the fix/remove-embedded-doc-complexity branch 7 times, most recently from acf9508 to 950dce6 Compare March 28, 2015 02:16
@alcaeus
Copy link
Member

alcaeus commented Jun 22, 2015

Looks good to me. The issues I previously reported are gone. 👍

@malarzm
Copy link
Member

malarzm commented Jun 22, 2015

@AronSzigetvari got any feedback for me by any chance? :)

@AronSzigetvari
Copy link

@malarzm, I have made a testing for the original problem and it seems to be OK, but I still have a failing test in the application test suite that I want to simplify to a minimal test or find out if we just used it wrong and had worked until now just because of some quirk.

@malarzm
Copy link
Member

malarzm commented Jun 23, 2015

@AronSzigetvari sure, do you think you'll be able to pull it together today or tomorrow?

@AronSzigetvari
Copy link

@malarzm I am on it now so I very much hope so.

@malarzm
Copy link
Member

malarzm commented Jun 23, 2015

@AronSzigetvari thank you very much! 👍

@AronSzigetvari
Copy link

@malarzm I have found the cause of our failing test, but I am not sure if it is a bug or not (a feature, or a fix of a previous bug):

Scenario: merging 2 carts. Cart is document, Item is embeddedDocument.
When we merged cart A and cart B, we added Items of cart B to cart A. Since it is the same Item object, after we call $dm->remove($cartB), we still have both items in $cartA->getItems(), but after calling $dm->flush(), the item that belongs to the removed $cartB is removed from $cartA, too.

I could make the test pass 2 different ways:

  1. If I don't use the same Item object, but create a new one with the same data: $cartA($item->copy())
  2. It also seems to work if we call $cartB->removeItem($item) when transferring items, so when we flush, the items doesn't belong to the removed parent document any more. (I am not sure if it is really OK, or may cause problems later)

It makes sense since remove is cascaded, but it used to work differently before, (however, persist should be also cascaded)
It is a BC for sure, but I am not sure it is a bug.

What do you think?

@malarzm
Copy link
Member

malarzm commented Jun 23, 2015

@AronSzigetvari I would love to be able to just reuse embedded documents by passing them around to different documents but unfortunately we're not aware of any good solution for that :( I'd suggest going down 1), I'm personally always (deep) cloning objects that are about to change owner to ensure nothing will clash or have any side effects.

malarzm added a commit that referenced this pull request Jun 24, 2015
@malarzm
Copy link
Member

malarzm commented Jun 24, 2015

Merged manually in b1089b7. @AronSzigetvari @blockjon @alcaeus @danez thank you very much for all your help!

@AronSzigetvari
Copy link

I have made a test that creates an owner document and an embedded document inside, then replaces the embedded, creates a new one with colliding hash value and checks the document state in the UOW. This fails with BETA10 and passes after this fix.
Probably too late to commit it in, since you have already merged the fix.

@malarzm
Copy link
Member

malarzm commented Jun 24, 2015

@AronSzigetvari I've merged @danez test in 4817908 but if you think it's not enough feel free to submit a PR with passing test only :)

@AronSzigetvari
Copy link

@malarzm I have added a test, it is a bit similar to @danez 's, but it is a slightly different case (no detached documents were used)

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

Successfully merging this pull request may close these issues.

Document is upserted and then updated during one flush operation
9 participants