Hi all,
Since some days, I have a problem to update two primary keys in table and I don't find why. That's weird because other fields are updated.
Example : ( langueId = 1; currencyId = 1)
$country = Country::findFirst(1);
$country->langueId = 2;
$country->currencyId = 1;
$country->isoCode = 'en' ;
$country->isoCode = '';
$country->updatedAt = date('Y-m-d H:i:s');
$country->update();
No Changes for langueId and currencyId. They still the same value after update; Can someone help plz ?
My Sample Country Model
<?php
namespace Some\Model;
class Country extends \Phalcon\Mvc\Model
{
public $id;
public $langueId;
public $currencyId;
public $isoCode;
public $active;
public $createdAt;
public $updatedAt;
public function initialize()
{
$this->belongsTo("langueId", "Some\Model\Langues", "id", array('alias' => 'langue'));
$this->belongsTo("currencyId", "Some\Model\Currency", "id", array('alias' => 'currency'));
}
public function getSource()
{
return 'countries';
}
}
My Sample Currency Model
<?php
namespace Some\Model;
class Langues extends \Phalcon\Mvc\Model
{
public $id;
public $isoCode;
public $languageCode;
public $active;
public $createdAt;
public $updatedAt;
public function initialize()
{
$this->hasOne("id", "Some\Model\Country", "langueId", array( 'alias' => 'country'));
}
public function getSource()
{
return 'langues';
}
}
My Sample Country Model
<?php
namespace Some\Model;
class Currency extends \Phalcon\Mvc\Model
{
public $id;
public $name;
public $isoCode;
public $isoCodeNum;
public $symbol;
public $active;
public $createdAt;
public $updatedAt;
public function getSource()
{
return 'currencies';
}
public function initialize()
{
$this->hasOne("id", "Localization\Model\Country", "currencyId", array( 'alias' => 'country'));
}
}
SQL Schema
-- -----------------------------------------------------
-- Table `langues`
-- -----------------------------------------------------
`langues` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`isoCode` VARCHAR(3) NULL,
`languageCode` VARCHAR(5) NULL,
`active` TINYINT(1) NULL,
`createdAt` DATETIME NULL,
`updatedAt` DATETIME NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `currencies`
-- -----------------------------------------------------
`currencies` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(32) NULL,
`isoCode` VARCHAR(3) NULL,
`isoCodeNum` VARCHAR(3) NULL,
`symbol` VARCHAR(8) NULL,
`active` TINYINT(1) NULL,
`createdAt` DATETIME NULL,
`updatedAt` DATETIME NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `countries`
-- -----------------------------------------------------
`countries` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`langueId` INT UNSIGNED NOT NULL,
`currencyId` INT UNSIGNED NOT NULL,
`isoCode` VARCHAR(3) NULL,
`active` TINYINT(1) NULL,
`createdAt` DATETIME NULL,
`updatedAt` DATETIME NULL,
PRIMARY KEY (`id`, `langueId`, `currencyId`),
INDEX `fk_countries_langues1_idx` (`langueId` ASC),
INDEX `fk_countries_currencies1_idx` (`currencyId` ASC),
CONSTRAINT `fk_countries_langues1`
FOREIGN KEY (`langueId`)
REFERENCES `langues` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_countries_currencies1`
FOREIGN KEY (`currencyId`)
REFERENCES `currencies` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Any Idea ?