나는 판매 및 팔로우 모델을 가지고 있습니다. 다음 테이블에는 id, user_id 및 sale_id가 있습니다. 내가 원하는 것은 sales_controller에서 인증 된 user_id와 매개 변수로 전달 된 sale_id가있는 추적 레코드를 하나씩 찾아야한다는 것입니다. ,다른 모델의 레코드 삭제
시도 1,
App::import('model','Follow');
$follow = new Follow();
$follow->user_id = $this->Auth->user('id');
$follow->sale_id = $id;
$follow->delete();
시도 2,
App::import('model','Follow');
$follow = new Follow();
$follow->delete(array('Follow.user_id'=>$this->Auth->user('id'), 'Follow.sale_id'=>$id));
시도 3,
App::import('model','Follow');
$follow = new Follow();
$result = $follow->find('first',array('conditions'=>array('Follow.user_id'=>$this->Auth->user('id'), 'Follow.sale_id'=>$id)));
$result->delete()
시도 4 : 그래서 여기
내가 무엇을 시도했다입니다
var $uses = array('Sale', 'Follow');
(...)
$result = $this->Follow->find('first',array('conditions'=>array('Follow.user_id'=>$this->Auth->user('id'), 'Follow.sale_id'=>$id)));
$result->delete();
시도 3과 4에서 $result
은 예상했던 값을 반환하지만 삭제가 작동하지 않습니다.
그러나 이러한 시도 중 아무 것도 해결되지 않았습니다. 컨트롤러의
('Follow' 개체를 새로 만드는 대신) 기준에 맞는 레코드를 먼저 가져 와서 그 위에서'delete()'를 호출 할 수 없습니까? 가장 효과적인 방법은 아니지만 액티브 레코드가 작동하는 것처럼 보입니다 ... – Franz
하지만 $ this-> 내가 할 수있는 일은 다음과 같습니다. App :: Import? 나는 다음을 찾는다 : $ this-> Follow-> find ('first', array ('conditions'=> 배열 ('Follow.user_id'=> $ this-> Auth-> user ('id') , 'Follow.sale_id'=> $ id)))하지만 결과가 반환되지 않았습니다 ... 제가 여기서 뭔가 잘못하고 있습니까? – Canastro