Quantcast

Zend\Db\TableGateway insert (...) on duplicate key update

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Zend\Db\TableGateway insert (...) on duplicate key update

Jurian Sluiman-3
For my service layer I would love to have just a $service->persist($object) where I do not bother whether this is persisted with an insert or update. I could accomplish this with an "INSERT <values> ON DUPLICATE KEY UPDATE" sql statement. 

I searched through the docs, but couldn't find anything related to this. I can use raw sql, but I prefer the TableGateway pattern (especially when I can use a HydratingResultSet and ClassMethods hydrator). My service interface would then look very simple:

interface Service
{
  public function find($id);
  public function findAll();
  public function findBy(Criteria $criteria);

  public function persist($object);
  public function remove($object);
}

I could split persist($object) into an insert() and update(), but I just wonder whether this is possible or not?
--
Jurian Sluiman
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Zend\Db\TableGateway insert (...) on duplicate key update

David Muir-2
On 05/07/12 16:39, Jurian Sluiman wrote:
For my service layer I would love to have just a $service->persist($object) where I do not bother whether this is persisted with an insert or update. I could accomplish this with an "INSERT <values> ON DUPLICATE KEY UPDATE" sql statement. 

I searched through the docs, but couldn't find anything related to this. I can use raw sql, but I prefer the TableGateway pattern (especially when I can use a HydratingResultSet and ClassMethods hydrator). My service interface would then look very simple:

interface Service
{
  public function find($id);
  public function findAll();
  public function findBy(Criteria $criteria);

  public function persist($object);
  public function remove($object);
}

I could split persist($object) into an insert() and update(), but I just wonder whether this is possible or not?
--
Jurian Sluiman

Isn't this because that syntax is a MySQL extension to standard SQL?
Same with REPLACE syntax.

David
Loading...