Yii Framework Forum: Afterdelete on AR with composite primary key - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Afterdelete on AR with composite primary key Rate Topic: -----

#1 User is offline   cyanatide 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 10-August 11

Posted 19 May 2017 - 02:24 PM

Hi!
Here is my table:
CREATE TABLE t_site_establishment_allocation
(
  f_site_id character varying(255) NOT NULL,
  f_establishment_id serial NOT NULL,
  CONSTRAINT t_site_establishment_allocation_f_establishment_id_fkey FOREIGN KEY (f_establishment_id)
      REFERENCES t_site_establishment (f_establishment_id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE,
  CONSTRAINT t_site_establishment_allocation_f_site_id_fkey FOREIGN KEY (f_site_id)
      REFERENCES t_site (f_site_id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
)


Now, I want to execute some code on delete.
I have an ajax function sending to this controller:
public function actionUnallocate()
{
        $establishmentAssociation = t_site_establishment_allocation::model()->findByPk(array('f_establishment_id' => $_GET['establishment_id'], 'f_site_id' => $_GET['site_id']));
        $establishmentAssociation->delete();
}


On that case, I have an error "Column name must be either a string or an array". I don't understand why...
So I have changed my code with this:

public function actionUnallocate()
{
       t_site_establishment_allocation::model()->deleteAll('f_establishment_id=:establishmentId AND f_site_id=:siteId',array(':establishmentId'=>$_GET['establishment_id'], ':siteId'=>$_GET['site_id']));
}


This code works, but apparently my function afterdelete is not executed... Is that because I use a deleteAll?
Thanks!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users