I use Phalcon 2.0.9 and I have this same problem. I have 2 foreign keys and when i try to update it, i become no errors and my SQL query is like yours:
UPDATE `users` SET `name` = 'testUSER', `email` = '[email protected]', `password` = 'FGbAaj8etqTu0HIp3DSGd3bOOLqNHUW', `mustChangePassword` = 'N', `notyficationId` = '0', `banned` = 'Y', `suspended` = 'Y', `active` = 'Y' WHERE `id` = '31' AND `profilesId` = 3 AND `companyId` = '3'
Here my PHP code:
...
$user = Users::findFirst($id);
...
$user->assign(array(
'name' => $this->request->getPost('name', 'striptags'),
'email' => $this->request->getPost('email', 'email'),
'profilesId' => $this->request->getPost('profilesId', 'int'),
'companyId' => $this->request->getPost('companyId', 'int'),
'banned' => $this->request->getPost('banned'),
'suspended' => $this->request->getPost('suspended'),
'active' => $this->request->getPost('active'),
'password' => $this->security->hash($this->request->getPost('password'))
));
if (!$user->update()) {
...
profilesId and companyId are the foreign keys and we can see that they moved to the WHERE clause.
@dschissler: i try $user->update(0 but without success....
I would be grateful for a solution or workaround,
Cheers Damian
=================
EDIT:
Today I had more time so I decided to test a few things.
I remove the 2 foreign keys from my schema the and after this the update/save behavior works correctly,
it was tested on version 2.0.8 and 2.0.9, could it be a BUG?
Here my old SQL schema (with foreign keys):
CREATE TABLE IF NOT EXISTS `blob`.`users` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` CHAR(60) NOT NULL,
`mustChangePassword` CHAR(1) NULL DEFAULT NULL,
`profilesId` INT(10) UNSIGNED NOT NULL,
`companyId` INT(10) UNSIGNED NOT NULL,
`notyficationId` INT(10) NOT NULL,
`banned` CHAR(1) NOT NULL,
`suspended` CHAR(1) NOT NULL,
`active` CHAR(1) NULL DEFAULT NULL,
PRIMARY KEY (`id`, `profilesId`, `companyId`),
INDEX `profilesId` (`profilesId` ASC),
INDEX `companyId` (`companyId` ASC),
CONSTRAINT `users_profiles`
FOREIGN KEY (`profilesId`)
REFERENCES `blob`.`profiles` (`id`)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT `users_company`
FOREIGN KEY (`companyId`)
REFERENCES `blob`.`company` (`id`)
ON DELETE RESTRICT
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 16
DEFAULT CHARACTER SET = utf8;
and here my new one (without foreign keys)
CREATE TABLE IF NOT EXISTS `blob`.`users` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` CHAR(60) NOT NULL,
`mustChangePassword` CHAR(1) NULL DEFAULT NULL,
`profilesId` INT(10) UNSIGNED NOT NULL,
`companyId` INT(10) UNSIGNED NOT NULL,
`notyficationId` INT(10) NOT NULL,
`banned` CHAR(1) NOT NULL,
`suspended` CHAR(1) NOT NULL,
`active` CHAR(1) NULL DEFAULT NULL,
PRIMARY KEY (`profilesId`, `companyId`),
INDEX `profilesId` (`profilesId` ASC),
INDEX `companyId` (`companyId` ASC))
ENGINE = InnoDB
AUTO_INCREMENT = 16
DEFAULT CHARACTER SET = utf8;
after these changes the query is again correct
UPDATE `users` SET `name` = 'testUSER', `email` = '[email protected]', `password` = 'FGbAaj8etqTu0HIp3DSGd3bOOLqNHUW', `mustChangePassword` = 'N', `profilesId` = '2', `companyId` = '5', `notyficationId` = '0', `banned` = 'Y', `suspended` = 'Y', `active` = 'Y' WHERE `id` = '31