Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 2.1
-
Component/s: Mapping Drivers
-
Security Level: All
-
Labels:None
Description
To be honest I feel like I saw this mentioned somewhere, but after looking around I couldn't find it, so I'll just post this anyway.
I'd like the ability to set a property as the associative key on ArrayCollections. This functionality could probably be done in a PostLoad by iterating over the objects, but it seems like ArrayCollection should be able to handle this functionality already, it's just a matter of modifying the mapper/parser.
Example:
/**
* @Entity
*/
class Object
{
//... $id column and anything else ...
/**
* @OneToMany(targetEntity="Param", mappedBy="object")
*/
protected $params;
//...
public function getParam($name)
{
return $this->params[$name];
}
}
/**
* @Entity
*/
class Param
{
/**
* @ManyToOne(targetEntity="Object")
* @JoinColumn(name="object_id", referencedColumnName="id", nullable="false")
*/
protected $object;
/**
* @Column(type="string")
*/
protected $name;
/**
* @Column(type="string")
*/
protected $value;
}
If you were able to specify an ArrayCollection key column then you would be able to have functions like getParam without having to loop over the objects in the collection. Something like:
@OneToMany(targetEntity="Param", mappedBy="object", collectionKey="name")
Issue Links
Activity
Benjamin Eberlei
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Summary | ArrayCollection Key Column | ArrayCollection Key Column @indexBy |
| Fix Version/s | 2.1 [ 10022 ] |
Benjamin Eberlei
made changes -
Benjamin Eberlei
made changes -
Benjamin Eberlei
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Assignee | Roman S. Borschel [ romanb ] | Benjamin Eberlei [ beberlei ] |
| Resolution | Fixed [ 1 ] |
Benjamin Eberlei
made changes -
| Workflow | jira [ 10718 ] | jira-feedback [ 14223 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback [ 14223 ] | jira-feedback2 [ 16087 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback2 [ 16087 ] | jira-feedback3 [ 18340 ] |
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-250, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
As much as I would like this I doubt it is
possiblefeasible. Imagine the name column of your Param object not being unique for you your linked Object..? How could the ArrayCollection know which instance to add to the collection and which one not?