-
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
Value objects (Based on #634) #835
Conversation
… to make parsing work.
…lectionProxy object, bypassing changes to UnitOfWork, Persisters and Hydrators.
…L test with Object and Array Hydration.
Conflicts: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-2773 We use Jira to track the state of pull requests and the versions they got |
$fieldMapping['declaredField'] = $property; | ||
$fieldMapping['originalField'] = $fieldMapping['fieldName']; | ||
$fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName']; | ||
$fieldMapping['columnName'] = $property . "_" . $fieldMapping['columnName']; |
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.
This probably needs to be delegated to the strategy handling automatic column generation instead of doing it inline here.
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.
You mean as an additional method?
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.
No Doctrine\ORM\Mapping\NamingStrategy
handles automatic naming of columns based on class and field names. However changing the interface is obviously a BC break. I think its small enough and easy enough to handle to make it, we need a mention in UPGRADE
file though.
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.
done
On Fri, Nov 1, 2013 at 9:33 PM, Benjamin Eberlei
[email protected]:
In lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:
$this->embeddedClasses[$mapping['fieldName']] = $this->fullyQualifiedClassName($mapping['class']);
- }
- /**
\* Inline the embeddable class
*
\* @param string $property
\* @param ClassMetadataInfo $embeddable
*/
- public function inlineEmbeddable($property, ClassMetadataInfo $embeddable)
- {
foreach ($embeddable->fieldMappings as $fieldMapping) {
$fieldMapping['declaredField'] = $property;
$fieldMapping['originalField'] = $fieldMapping['fieldName'];
$fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName'];
$fieldMapping['columnName'] = $property . "_" . $fieldMapping['columnName'];
No Doctrine\ORM\Mapping\NamingStrategy handles automatic naming of
columns based on class and field names. However changing the interface is
obviously a BC break. I think its small enough and easy enough to handle to
make it, we need a mention in UPGRADE file though.—
Reply to this email directly or view it on GitHubhttps://github.com//pull/835/files#r7380794
.
* | ||
* @return string | ||
*/ | ||
function embeddedFieldToColumnName($propertyName, $embeddedColumnName); |
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.
Would be nice to have $entityClass
and $embeddedClass
$embeddedObject = $this->parentProperty->getValue($object); | ||
|
||
if ($embeddedObject === null) { | ||
$embeddedObject = new $this->class; // TODO |
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.
How about changing this to use the unserialize
trick, or did you have something else in mind?
@guilhermeblanco Feedback please, this is mergable from my POV. |
I played around with the new functionality and encountered a problem with embeddables inside embeddables. |
Thanks a lot guys. |
Finally the feature was added :) Thank you all who contributed. Maybe we can now look forward to adding support for mapping collections of embeddable objects |
private $childProperty; | ||
private $class; | ||
|
||
public function __construct($parentProperty, $childProperty, $class) |
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.
Aren't these parameters missing some typehint ? As it is used as (possibly ?) ReflectionProperty afterwards...
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.
@Taluu see standing TODO
in the class header`.
@alsar Ah yes, i have to disable doing that for now. Its not yet supported. |
@sherifsabry20000 a collection of embeddable objects is just a |
Thanks a lot guys. |
Is it possible to use, for example, Address as both an entity and an embeddable? A contrived example, that has a basis in our application. Let's say I have an entity In addition, each Would we have to define two things with the basically the same definition (i.e., an Does that make sense? Or, am I thinking about the problem in entirely the wrong way? |
@mbadolato an entity has an ID, an embeddable doesn't, so I don't think it makes sense here. I'd also suggest moving these discussions to the mailing list |
@Ocramius Re: having an id vs not having an id: Yep, hence my question. |
@mbadolato I thought that was possible. The use case would be an invoice and a customer associated with it. When you create an invoice almost full customer information should be persisted together with it. |
I don't think that is possible just yet as we just have a single metadata On Tue, Feb 11, 2014 at 11:14 AM, Miha Vrhovnik [email protected]:
|
That's what I was confirming. Thanks @schmittjoh. @mvrhov Yes that is a good example of a use case for it. |
@beberlei How can you use manyToOne relation between entities and embeddable element ? |
@fpaterno please open a new issue at http://www.doctrine-project.org/jira/browse/DDC or ask on the mailing list. |
@mvrhov then you should have |
I'm quite enthousiastic about Embeddables being added to Doctrine, but it's a pity that true Value Objects, which are compared by their properties, are not supported yet. Given a Value Object The following is now supported: But then you should know the internal properties when writing your query. That's not how Value Objects usually are compared. Instead, I expect to be able to do this: A complicating factor is that Value Objects are Embeddables, but not every Embeddable is a Value Object. So there is always the question if objects need to be compared by reference or by their properties. So, perhaps it's an idea to introduce a special operator Finally, for those who would also like more support for Value Objects, please check out my pull request for Collections. It expresses the same ideas for in-memory collections and adds the Just some thoughts and ideas. I'd love to hear some discussion on this as I think it would make Doctrine really powerful in supporting rich, expressive domain models. |
please open a ticket in the issue tracker for this feature request rather than commenting on a merged PR. Otherwise the discussion will get lost |
@erik-am 👍 |
@stof Thanks for pointing me to the right direction. I created an issue for it: http://www.doctrine-project.org/jira/browse/DDC-3154 |
This thread would probably be a good candidate for the new Github Conversation Lock |
@mbadolato I don't see any fights going on, though yes, if anyone else has anything to add, please do so with a new issue on our issue tracker at http://www.doctrine-project.org/jira/ or on the mailing list at https://groups.google.com/forum/#!search/doctrine-user |
This is PR #634 with the following additional changes: