-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
DDC-3730: Embeddable hydrates to object instead of null #4568
Comments
Comment created by eugene-d: See #1275 |
This is actually really confusing definitely when you combine it with the docs |
I must say I find this rather a bug than an improvement... agree with @boekkooi regarding the docs... |
well this is #4568; and #4670 is rather a duplicate of #1275, both actually "features" or "improvements". This here however is a Bug because embeddables whose all properties are nullable and being null hydrate to an empty object when being stored as null. This is misleading (saving != retrieving) and not according to the docs. |
@afoeder the order of the tickets is scrambled due to the fact that they were imported from Jira in December, heh |
Hi @Ocramius Has there been any further discussion on this topic? We've just hit into the same problem as described here on our first Doctrine project. Let me know if there's anything we can do to help — provide usage examples, code samples, discussions, etc. |
@Harrisonbro as it currently stands, doctrine will not support nullable embeddables. That functionality may be implemented later, by implementing embeddables as hidden one-to-one records. |
OK. Is there any way for us to implement this on a case-by-case basis (eg. by hooking into the hydration process of an embeddable somehow) so we can manually check whether specific embeddables have enough data in the database to be considered 'valid' and therefore hydratable? Obviously we're not keen to allow value objects to be instantiated in an invalid state and then check an |
Then just use the lifecycle system to (de-)hydrate VOs on your own, no? |
Do you mean lifecycle callbacks — maybe I’m almost certainly missing something here, sorry. Rather new to |
@Harrisonbro the idea is to NOT use embeddables there, and use a lifecycle listener to replace fields with embeddables then (manually). Doctrine will not implement nullability for embeddables for now. |
OK, gotcha. So in the example I gave — a If so, that seems workable and means the entity is responsible for checking if the VO should be instantiated (rather than having the VO able to be ‘invalid’ and have to implement an Example code of what I mean: class Product
{
private $sale_price_amount;
private $sale_price_currency;
public getSalePrice() : SalePrice
{
if (
is_null($this->sale_price_currency) ||
is_null($this->sale_price_amount)
) {
return null;
}
return new SalePrice(
$this->sale_price_currency,
$this->sale_price_amount
);
}
} Is that something like what you’re suggesting instead of nullable embeddables? |
Correct. Basically, since this is a scenario that Doctrine can't cover right now (because of how RDBMS DDL works), you can just implement it in userland for the few times where it pops up. |
OK great, thanks a lot for the help.
|
Thanks, I silently kept up reading your conversation :)
|
I like that approach, @afoeder — you still do an I suppose the major downside of your approach is that you do still have a VO in an inconsistent state, whereas if you don't let Doctrine hydrate the VO as an embeddable you avoid this; a bit more boilerplate & checking code, but you never have a VO in an invalid state. Really it's just a trade-off between the 2 options. Others reading this should just be aware of the 2 options and their various merits. |
I would have preferred to comment on #1275, but the present issue has the benefit to be still open. My 2 cents on the sensitive subject of nullable embedded properties:
Finally, you only have a real problem when you have a fully nullable embeddable, and want to make the distinction between a The previous two bullet points, however, I would strongly suggest working on them ASAP. I'll be happy to help, provided that lead developers are happy with the concept. |
Thanks for that clear explanation, @BenMorel. I quite agree with your suggested specification of how Doctrine should behave, and that it should be worked on. This issue is the top priority I'd like to see addressed in doctrine. I too would be happy to help out with the development and testing of this, if the Doctrine team agree. |
We came across the same issue, in our domain a Well, it only requires knowledge on the embeddable itself, but easy workaround for now. I hope this helps other developers until the issue will be resolved by Doctrine. |
@havvg How to use this workaround? For example I have User entity with embeddable class Gender. Something like that: I know that I need the User entity should have registered postLoad listener NullableEmbeddableListener but I have no idea how to register it. Can you provide any example? I guess that I need somewhere call addMapping? |
@BenMorel did you by any chance work on a PR for this? I'd really hope to have this "bug" resolved, but I don't understand doctrine well enough to be able to write a pretty PR for this issue. |
@Evertt Not yet, and I won't until I get the green light from lead developers. I've invested a lot of time in other pull requests, that have been open for years and are still not merged. I can't waste any more time on this project I'm afraid! |
@BenMorel that's too bad and I totally understand! It's sad that huge projects like these at some point seem to slow down to a point that it just seems frozen. |
That's the dark side of open source: projects rely solely on the free time developers can invest in them, and at some point they're just too busy on other businesses and/or family life to carry on with developments. I, too, feel like Doctrine is slowing down; it's just unfortunate that there aren't enough (available) lead developers to keep up the pace with pull requests: many developers are there to offer their help, but without enough consideration from project leaders, it's just wasted brain processing time. |
doctrine 2.x is frozen because doctrine 3 is actively developing (I read somewhere post by @Ocramius) |
@szepczynski except that there's no ETA for doctrine 3 so that could take years for all we know. If it really takes that long it would be nice for improvements to still be added to doctrine 2. |
It would make it a mess to migrate these additions to something completely redesigned. From what I can see in the last dozen releases, doctrine functionality already abundantly covers the 90% of use-case scenarios, so we could even call it "feature complete", if it wasn't for some rough edges that you encounter when you explore more shady features. |
@Ocramius I wouldn't call this issue right here a "shady feature". I think this is a very essential part of the embeddables system. |
Right, and embeddables have barely been added in |
@Ocramius Sorry to pollute this thread, but would the transaction object and default lock mode fit in 3.0? |
@BenMorel most likely, yes |
@Ocramius I'm not sure I understand you right. Do you mean they will come back in 3.x after their internal working mechanisms have been rewritten? |
@Evertt yes, but likely as completely rewritten/redesigned. |
@Ocramius Are there ways we can help the development of Doctrine, either v2 or v3? It's a tool we all use so would love to,support development if a can. (Sorry to pollute this thread but not sure where else to write.) |
@Harrisonbro https://github.com/doctrine/doctrine2/milestones/3.0 Let's please stop going further OT. If you have a question, make a new issue. |
FTR: there is a small 3rd party library that provides a listener for setting embedded entities that are all null to null (the gist that was discussed above): https://github.com/tarifhaus/doctrine-nullable-embeddable |
@BenMorel With all due respect, I have to go r/quityourbullshit on you here:
For Doctrine 2, there are 26 pull requests from you: 2 Open, 2 Closed without merge (one was fixed differently, one would introduce a lot of pain with future pull requests), and 22 merged. Feel free to point out pull requests that you are waiting to get merged, but please don't say stuff like that without backing it up when other people sacrifice lots of free time to get you free software. Thank you. |
@alcaeus Thanks for investing your time investigating my contributions to this repository. You have already wonderfully pointed out my unmerged pull requests, you just forgot to mention their opening date:
I did invest quite a lot of time on these two pull requests, and since 2 years I am getting next to no feedback, despite multiple attempts to draw attention from the team. Yes, I had PRs merged as well (did I ever say I didn't?), but the lack of feedback on these last two blocked my motivation to contribute further to this project for now.
I hope I have backed it up to your taste, and rest assured that I know quite well what it's like to sacrifice some time on free software. Cheers. |
@BenMorel the way you made it sound was that people completely disregarded your work, which they don't. That's why I took the time to look through your contributions to see what's going on. As for the pull request you mentioned, (please keep in mind that I'm not an ORM guy) it looks like it's a fairly large pull request that touches transaction logic in the DBAL, affecting most of what it (and thus ORM) does. Pull requests like that take time to review and evaluate. I'm not trying to make excuses for other people here, I'm just hoping you can bear with the people maintaining it. That said, there is currently a development push going for 3.0, so maybe there's an opportunity to get those pull requests merged. Open source projects need contributors to move forward and evolve, especially when maintainers have little or in some cases no time for the project. However, writing pull requests is just a small part of that work - most of it is looking at issues, figuring out what's going on, evaluating pull requests and making sure your user base is not going to burn you at the stake because you messed up. That can be very time consuming and tiring, so unfortunately, large pull requests are often the first to stay open simply because of the effort it takes to review and merge them. |
@BenMorel I agree with you. The Doctrine mantra I keep hearing seems to be along the line of "Well, it kind of works in most cases and changing things is hard so let's not do it". They say a picture says a thousand words and I think this picture sums up my feelings about Doctrine right now: Disclaimer: Owners, don't take offense - it's meant in a lighthearted way and is just my personal opinion. I know you work hard on this, and for that I thank you. I just disagree a bit with the general negativity that I personally see towards any major changes. I know you're working on 3.0 but Symfony and others are leaving you in the dust. If there's too much work, consider giving other contributors more rights or bumping the major version more often so that there can be BC breaks. |
@ryall I think that's the nail on the coffin then. Here's the exit: Closing and locking. |
Jira issue originally created by user pcnc:
Good afternoon,
When hydrating an Embeddable with nullable attributes the result is an instance of the Embeddable class , this is obviously correct and expected behavior.
If all the attributes are null the hydrator will still return an instance of the class with all of its properties null , even if I persist and flush my Entity with the Embeddable being set as null .
For clarification :
Calling $newEntity->getMyEmbeddable() will return an instance of the MyEmbeddable object with all of it's attributes set to null .
I expected $newEntity->getMyEmbeddable() to be NULL .
Can someone clarify is this is expected behaviour ? In case it is , how can I achieve what I'm looking for ?
Best regards
The text was updated successfully, but these errors were encountered: