-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Refactoring hydrator #106
Refactoring hydrator #106
Conversation
I added some strategies example so that you can see the logic. Do you think this is good ? Not sure about the naming or namespaces (should it be DoctrineModule\Stdlib\Hydrator\Strategy\Collection...) ? |
Question : for by value, we clone when it's a toOne relationship. However, what happen when a proxy is cloned ? Can this be a problem ? |
Ok I will change that tomorrow. I don't have a lot of time (I need to prepare my tomorrow's webinar). I'll work more on it tomorrow and try to implement the first strategy as an example. Then I'll wait ocramius feedback to check if this is the best way to do. |
@Ocramius , could you starting to review this so we can work more on it ? I have had several people pinging me on IRC and on my blog for issues with the current hydrator when used with strategies. The current hydrator uses the ClassMethods hydrator inside and it makes things not intuitive at all, so it would be cool if we could work on this one, as it solves this issue by not relying on the ClassMethods hydrator. |
@Ocramius , @davidwindell , I worked on it. I think it's finished. I've implemented the two default strategies for Collections (AllowRemove and DisallowRemove). The hydrator code is now simpler to the end-user to as it does not rely on ClassMethods hydrator, so strategy attached to fields are directly executed. It also add the by-value and by-reference logic (although, to be honest, I still don't understand why people would need the by reference method). I just need to write tests. |
Owwwww, my fault :( Here and on #119 (which I'm thinking of rewriting personally, but at filter level) Let me get drunk in a couple of hours and then I'll be back and ready =D |
No problem. Have fun tonight :). Envoyé de mon iPhone Le 31 déc. 2012 à 17:50, Marco Pivetta notifications@github.com a écrit :
|
Need to tweek performacne a little bit I suppose... |
Hi everyone, First of all, I wish all of you a happy new year, and lot of fun with Doctrine this year ! Concerning the hydrator refactoring, I added a tons of tests (and rewrite all of them) so now the coverage is pretty solid. You can completely review it @Ocramius . Some notes:
EDIT : I figured out that we can't get a Reference to an object using an ObjectRepository (don't know why...), and we can't access to the ObjectManager from an ObjectRepository too... However the getReference is needed in the specialization of the hydrator in Doctrine ORM to avoid to fetch the object from database (but just get a reference). That's why I moved to the object manager + class of the entity.
OKEY, now I'm going to write documentation :). |
Thanks for your hard work @bakura10 looking forward to giving this one a spin. |
…return associations
$values = new ArrayCollection(); | ||
foreach ($data as $field => $value) { | ||
// Ignore unknown fields or null values | ||
if ($value === null || !$refl->hasProperty($field)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, yoda + it is not clear why you skip on null (may want to add a comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc it has because there was a test case about not hydrating null values. Someone added it. Furthermore, if you typehint your setter like this:
public function setFoo(Foo $foo);
It won't work, people need to write Foo $foo = null.
Don't know if we should allow null ?
@bakura10 coverage is awesome and this can be merged after addressing my comments. You should also use You should probably spawn a few issues about:
|
So, I change the since to since 0.7, I added the two strategies that work by reference, and I updated tests and doc. As I told you in IRC: Don't forget to merge this one in ORM too: doctrine/DoctrineORMModule#156 Furthermore, when you'll tag DoctrineORMModule, I think you need to change https://github.com/doctrine/DoctrineORMModule/blob/master/composer.json#L36 to "doctrine/doctrine-module": "=0.5.*", Otherwise I suppose that DoctrineORMModule will download latest hydrator and will break everything. |
Can we still set a relation to null or have you now removed that and the
|
For now no I didn't change that davidwindell. I've tried to port all the old tests to the new hydraotr. |
Fantastic!
|
@davidwindell Please see #139 for what you just commented. I asked bakura to remove the checks on null values, since if I explicitly set something to This is a validation problem IMO |
Changes Unknown when pulling e56a897 on bakura10:form/hydrator-refactoring into * on doctrine:master*. |
@davidwindell, @Ocramius
This is the beginning of the refactoring of the hydrator, using the byref/byval logic.
Basically, we get rid of the ClassMethods hydrator, people will have to follow some conventions on the naming.
The extracting phase is done (I hope) correctly for both byref/byval.
I still want ocramius to explain exactly why a user would need byref or byval (I mean, I know what by value and by reference means) but WHY it would chooose one over another).
For the hydrating phase, and to answer to davidwindell answer, I think that the cleanest way is to introduce strategy that are called when hydrating collections.
For instance, the intersectionUnion would become a "AllowRemove" strategy, so that if elements are not present in the posted collections, the strategy allow to remove them from the original collection, or a DisallowRemove that would do what david wanted (does not remove elements from original collection even if they are not posted).
The AllowRemove would need the user to define a removeSomethings, as well as a addSomethings that will be used to insert new elements.
What we need :