DDC-298: Allow Entity to hold a collection of a single primitive type #370

Open
opened 2026-01-22 12:36:13 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 2, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @beberlei:

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
<ins> elementTable
</ins> keyType
<ins> keyLength
</ins> keyColumnDefinition
<ins> valueType
</ins> 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

Originally created by @doctrinebot on GitHub (Feb 2, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @beberlei: 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 <ins> elementTable </ins> keyType <ins> keyLength </ins> keyColumnDefinition <ins> valueType </ins> 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
admin added the New Feature label 2026-01-22 12:36:13 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2010):

@doctrinebot commented on GitHub (Feb 2, 2010): - is duplicated by [DDC-2806: @ElementCollection does work as expected](http://www.doctrine-project.org/jira/browse/DDC-2806)
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Feb 2, 2010): Comment created by @beberlei: 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
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Feb 2, 2010): Comment created by @beberlei: Column Names should be Change-able also since there could be people who name their primary keys "key" and "value" o_O
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2010):

Comment created by @beberlei:

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.

@doctrinebot commented on GitHub (Feb 2, 2010): Comment created by @beberlei: 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.
Author
Owner

@doctrinebot commented on GitHub (Dec 24, 2010):

Comment created by @beberlei:

Pushed back

@doctrinebot commented on GitHub (Dec 24, 2010): Comment created by @beberlei: Pushed back
Author
Owner

@doctrinebot commented on GitHub (Oct 10, 2013):

Comment created by myknbani:

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

@doctrinebot commented on GitHub (Oct 10, 2013): Comment created by myknbani: Any news on this? It has been almost 3 years since its last update =)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#370