[DDC-298] Allow Entity to hold a collection of a single primitive type Created: 02/Feb/10  Updated: 20/Dec/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1
Fix Version/s: 2.x
Security Level: All

Type: New Feature Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 5
Labels: None

Issue Links:
Duplicate
is duplicated by DDC-2806 @ElementCollection does work as expected Resolved

 Description   

Sometimes you want to save arbitrary information for an entity using a key -> value array-structure. JPA supports this by means of the @ElementCollection annotation with allows to specify HashMaps for example.

I propose a new AssocationMapping called "ElementMapping" / "ElementCollection" and annotations (options):

ElementCollection
+ elementTable
+ keyType
+ keyLength
+ keyColumnDefinition
+ valueType
+ valueLength
+ valueColumnDefinition

The key and value definitions are necessary for converting and schema generation.

The implementation would make use of the PersistentCollection at all times and work as any other persistent collection just with primitive types.

Restrictions for a first implementation:

  • Only available as a Lazy-Load Collection, no hydration with the source entity
  • Can't be used in queries alike "entity.colname.key = ?1"

Use-Case:

$entity->options['foo'] = 'bar';
$entity->options['bar'] = 'baz';

This could be done for 2.0 imho, adding the necessary changes and optimizations could then be scheduled for 2.1



 Comments   
Comment by Benjamin Eberlei [ 02/Feb/10 ]

In this implementation Schema-Tool would generate a table:

elementTable (entity_id-1, ..., entity_id-n, key, value) and using the Platform Type Generation of keyType and valueType

Comment by Benjamin Eberlei [ 02/Feb/10 ]

Column Names should be Change-able also since there could be people who name their primary keys "key" and "value" o_O

Comment by Benjamin Eberlei [ 02/Feb/10 ]

Ordering could be implemented on top of this using the @OrderColumn JPA implementation by adding another column to the table with a numeric order that will be "order by"'d on select time.

Comment by Benjamin Eberlei [ 24/Dec/10 ]

Pushed back

Comment by Richard Michael Coo [ 10/Oct/13 ]

Any news on this? It has been almost 3 years since its last update =)

Generated at Fri Dec 19 02:21:07 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.