简体   繁体   中英

Doctrine Array Hydration with db column names keys

Using the latest Doctrine (2.4) Given this simple entity:

class Booking
{
    /**
     * @var integer
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var \DateTime
     * @ORM\Column(name="from_date", type="datetime", nullable=true)
     */
    protected $fromDate;

    /**
     * @var float
     * @ORM\Column(name="deposit_price", type="float", nullable=true)
     */
    protected $depositPrice;
}

If I do a simple ORM query with array Hydration the result I get back is something like this:

[
   'id'=>1,
   'depositPrice'=>100.5,
   'fromDate'=>'2012-01-01'
]

Is there a simple way to Hydrate using the actual column fields? To get a result like this:

[
    'id'=>1,
    'deposit_price'=>100.5,
    'from_date'=>'2012-01-01'
]

There are 3 solutions:

I would prefer 3rd case. It is so easy to rename your fields. You can do it on all files with regular expressions (if it is supported by your IDE).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM