2012-10-31 2 views
0

HABTM + cakephp에 문제가 있습니다.HABTM 메인 모델이 saveall()로 저장되었습니다.

public $hasAndBelongsToMany = array(

    'Cliente' => array(
     'className' => 'Cliente', 
     'joinTable' => 'tipos_comercio_cliente', 
     'foreignKey' => 'tipo_comercio', 
     'associationForeignKey' => 'cliente' 
    ) 
); 

양식이 게시되면, 내가 배열 $this->request->data에 있습니다

Cliente :

public $hasAndBelongsToMany = array(
    'TiposComercio' => array(
     'className'    => 'TiposComercio', 
     'joinTable'    => 'tipos_comercio_cliente', 
     'foreignKey'   => 'cliente', 
     'associationForeignKey' => 'tipo_comercio' 
    ) 
); 

TiposComercio 내 응용 프로그램에서

난 (관계 정의와 함께)이 모델을 가지고 이 :

array(

    'Cliente' => array(
     'password' => '*****', 
     'razao_social' => 'Teste', 
     'responsavel' => 'responsavel', 
     'cidade' => '1', 
     'cep' => '13560201', 
     'logradouro' => 'Log test', 
     'numero' => '', 
     'bairro' => '', 
     'complemento' => '', 
     'atividades' => '', 
     'username' => 'username11', 
     'TiposComercio' => array(
      (int) 0 => '1', 
      (int) 1 => '4' 
     ) 
    ) 

) 

$ this-> Cliente-> saveAll ($ this-> request-> data)을 실행할 때; ClientesController에서 다음과 같은 문제가 있습니다 :

  • 클라이언트 데이터가 저장됩니다. TiposComercio의 아무 것도 저장되지 않습니다.

무엇이 잘못 되었습니까?

감사합니다.

답변

2

데이터 배열의 구조가 잘못되었습니다. HABTM 데이터를 저장하기위한 매뉴얼을 읽어보세요 : http://book.cakephp.org/2.0/en/models/saving-your-data.html#saving-related-model-data-habtm의 예를 바탕으로

, 당신의 데이터 배열은 다음과 같이 형성해야합니다

array(
    'Cliente' => array(
     'password' => '*****', 
     'razao_social' => 'Teste', 
     'responsavel' => 'responsavel', 
     'cidade' => '1', 
     'cep' => '13560201', 
     'logradouro' => 'Log test', 
     'numero' => '', 
     'bairro' => '', 
     'complemento' => '', 
     'atividades' => '', 
     'username' => 'username11', 
    ), 
    'TiposComecio' => array(
     (int) 0 => '1', 
     (int) 1 => '4' 
    ) 
) 
+0

감사합니다 많이! 오류 수정 방법을 알려주세요! – matheusvmbruno