I am using symfony 2 with doctrine. I want to create custom id for the product table.
Eg:
Product code P1000-1 P1000-2 P1000-3
How to generate this ?
I am using symfony 2 with doctrine. I want to create custom id for the product table.
Eg:
Product code P1000-1 P1000-2 P1000-3
How to generate this ?
How about you write a small piece of custom function to retrieve the last inserted ID and then add 'P1000-' before the id. See below,
public function getLastInsertedId($entity)
{
$em = $this->getDoctrine()->getManager();
$result = $em->createQueryBuilder();
$last_inserted_id = $result->select('MAX(p.id) as id')
->from($entity, 'p')
->getQuery()
->getSingleResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
return 'P1000-'.$last_inserted_id['id'];
}
Hope this helps. Cheers!