Friday, May 4, 2012

Edit method in hasMany Model

Hello, guys.

I'm working with CakePHP 2.1.2 stable.

I search about this problem, but i don't found any solution.

This is the models-relationship:

Usuarios (Users)
UsuarioEmails (UserEmails)
UsuarioEndereco (UserAddress)

A User hasMany UserEmail and UserAddress.

In add method, i create the User and add news rows in the UserEmail
and UserAddress, with your values = NULL.
In the edit method, i want to edit theses rows with NULL values (from
UserEmail and UserAddress).
I want to use this edit method in User, to edit in one form all these
informations.

By the way, i have this in edit method:

http://bin.cakephp.org/view/1820438376

And this in edit view:

http://bin.cakephp.org/view/1154545357

But when i submit the form, the CakePHP rather than update the rows,
he create news rows.

3 INSERT INTO `---`.`tbl_usuarios` (`nome`, `modified`, `created`)
VALUES ('Luiz Henrique Almeida sada Silva', '2012-05-04 15:59:47',
'2012-05-04 15:59:47') 1 1 1
4 INSERT INTO `---`.`tbl_usuario_enderecos` (`usuario_id`, `endereco`,
`bairro`, `cidade`, `cep`, `ativo`, `modified`, `created`) VALUES (15,
'', '', '', '', '1', '2012-05-04 15:59:47', '2012-05-04 15:59:47') 1
1 1
5 INSERT INTO `---`.`tbl_usuario_emails` (`usuario_id`, `email`,
`senha`, `modified`, `created`) VALUES (15, 'luizhrqas@gmail.com',
'relogio123', '2012-05-04 15:59:47', '2012-05-04 15:59:47') 1 1 1
6 COMMIT

How i can do to the saveAssociated method update, rathe than insert
new rows?

Thanks, and sorry for my bad english. =)
Lhas
luizhrqas@gmail.com

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate