Hi all, I have several models, with associations, defined as following:
<?php
class Page extends \Phalcon\Mvc\Model {
public function initialize()
{
$this->belongsTo('voting_id', 'Voting', 'id', array('alias' => 'Voting', 'foreignKey' => true));
$this->hasMany('id', 'PageParameter', 'page_id', array('alias' => 'PageParameters', 'foreignKey' => true));
$this->hasMany('id', 'AnswerParameter', 'page_id', array('alias' => 'AnswerParameters', 'foreignKey' => true));
$this->hasMany('id', 'QuestionParameter', 'page_id', array('alias' => 'QuestionParameters', 'foreignKey' => true));
}
}
<?php
class PageParameter extends \Phalcon\Mvc\Model {
public function initialize()
{
$this->belongsTo('page_id', 'Page', 'id', array('alias' => 'Page', 'foreignKey' => true));
$this->belongsTo('parameter_id', 'Parameter', 'id', array('alias' => 'Parameter', 'foreignKey' => true));
}
}
<?php
class Parameter extends \Phalcon\Mvc\Model implements \Serializable
{
/**
* Parameter type
*
* @var integer
*/
protected $type;
public function initialize()
{
$this->hasMany('id', 'AnswerParameter', 'parameter_id', array('alias' => 'AnswerParameters', 'foreignKey' => true));
$this->hasMany('id', 'PageParameter', 'parameter_id', array('alias' => 'PageParameters', 'foreignKey' => true));
$this->hasMany('id', 'QuestionParameter', 'parameter_id', array('alias' => 'QuestionParameters', 'foreignKey' => true));
$this->hasMany('id', 'VotingParameter', 'parameter_id', array('alias' => 'VotingParameters', 'foreignKey' => true));
}
}
Then, while doing this cycle,
foreach ($this->page->pageParameters as $pageParameter) {
if ($pageParameter->getType() == self::PAGE_PARAMETER_TYPE
&& isset($this->parameters[$pageParameter->getIdentifier()])
&& $pageParameter->parameter->getType() == $this->parameters[$pageParameter->getIdentifier()]->getType()
) {
$dbParameter = $pageParameter->parameter;
$dbParameterValue = $dbParameter->getValue();
$dbParameter->setDefault($this->parameters[$pageParameter->getIdentifier()]->getDefault());
$dbParameter->setValue($dbParameterValue);
$this->parameters[$pageParameter->getIdentifier()] = $dbParameter;
}
}
the $dbParameter
is loaded from database, but $dbParameter->getType()
is returning string, even though in the database the field is integer, and if the Parameter
is instantiated, the value is set to integer constant.
Is there something to be set somewhere that I'm missing, or is it a bug?
Thanks for your help with this.