Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.1
-
Fix Version/s: None
-
Component/s: Mapping Drivers
-
Security Level: All
-
Labels:None
-
Environment:Using Doctrine ORM 2.1.0BETA1
Description
I am trying to index a collection by its entity's column which is also a foreign key (association). It seems to me that it is not possible at the moment.
For example:
/**
* @Entity
*/
class Hotel
{
// $id column and other stuff
/**
* @oneToMany(targetEntity="Booking", mappedBy="hotel", indexBy="room")
* @var Booking[]
*/
private $bookings;
}
/**
* @Entity
*/
class Booking
{
/**
* @var Hotel
*
* @Id
* @ManyToOne(targetEntity="Hotel", inversedBy="bookings")
* @JoinColumns({
* @JoinColumn(name="hotel_id", referencedColumnName="id")
* })
*/
private $hotel;
/**
* @var Room
*
* @Id
* @ManyToOne(targetEntity="Room")
* @JoinColumns({
* @JoinColumn(name="room_id", referencedColumnName="id")
* })
*/
private $room;
}
Only possible workaround I found is to define another (plain) entity's property mapped to the same table column and index by it:
/**
* @Entity
*/
class Hotel
{
// $id column and other stuff
/**
* @oneToMany(targetEntity="Booking", mappedBy="hotel", indexBy="roomId")
* @var Booking[]
*/
private $bookings;
}
/**
* @Entity
*/
class Booking
{
// ...
/**
* @var Room
*
* @Id
* @ManyToOne(targetEntity="Room")
* @JoinColumns({
* @JoinColumn(name="room_id", referencedColumnName="id")
* })
*/
private $room;
/**
* @var integer $roomId
*
* @Column(name="room_id", type="integer", nullable=false)
*/
private $roomId;
}
Wouldn't it be easy to support it?
Activity
Benjamin Eberlei
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Issue Type | Bug [ 1 ] | Improvement [ 4 ] |
Benjamin Eberlei
made changes -
| Workflow | jira [ 12679 ] | jira-feedback [ 13930 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback [ 13930 ] | jira-feedback2 [ 15794 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback2 [ 15794 ] | jira-feedback3 [ 18051 ] |
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-1180, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
It is not so easy to implement from the first gimplse and it is not a bug but an improvement/feature request.