Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-93

It would be nice if we could have support for ValueObjects

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      class User {
      	/**
      	 * @Column(type="string")
      	 */
      	private $address;
      	
      	/**
      	 * @Column(type="string")
      	 */
      	private $city;
      	
      	/**
      	 * @Column(type="string")
      	 */
      	private $state;
      }
      

      We could have:

      class User {
      	/**
      	 * @Component(class="Address")
      	 */
      	 private $address;
      }
      

      It would my life a lot easier....


      Notes for implementation

      Value objects can come in two forms:

      a) as embedded value objects
      b) as collections of value objects

      An implementation should concentrate on a) first. The following things all concentrate on a).

      DQL Support

      Conditions:

      1. "select f from Foo f where f.embedded.value = ?1" (setParameter(1, $scalarValue))
      2. "select f from Foo f where f.embedded = ?1" (setParameter(1, $embeddedValueObject))

      At least Nr.1 must be possible in a first implementation.

      Selecting:

      1. "select f from Foo f" must explode embedded value objects in the SQL SELECT clause.
      2. "select f.embedded from Foo f" must explode the columns of the embedded object in the SQL SELECT clause.

      At least Nr. 1 must be possible in a first implementation, obviously.

      Components affected (among others): Parser, SqlWalker, ...

      Persisters

      The persisters need to take embedded value objects into account when persisting as well as loading entities.

      Components affected (among others): Persisters, UnitOfWork, ...

      Metadata

      ClassMetadataInfo needs to be extended with a field (probably an array) that contains the mappings of embedded values.
      New annotations as well as XML/YAML elements are needed.

      Components affected (among others): ClassMetadataInfo, AnnotationDriver, YamlDriver, XmlDriver, doctrine-mapping.xsd, ...

      Change Tracking

      If value objects are supposed to be immutable this is easy and might require no or few changes. If, however, we want to track changes in mutable value objects it might get more complicated.

      Components affected (among others): UnitOfWork, ...

        Issue Links

          Activity

            People

            • Assignee:
              Guilherme Blanco
              Reporter:
              Avi Block
            • Votes:
              40 Vote for this issue
              Watchers:
              37 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: