Model News is associated with the Files one to one. Trying to do a relational query:

$model=News::model()->with('files')->findByPk($_GET['id']); 

If I have an entry in the files table corresponding to $_GET['id'] , then everything is ok. If there is no file, then throws an error:

 Fatal error: Call to a member function isAttributeRequired() on a non-object in C:\...\yii\framework\web\helpers\CHtml.php on line 1514 

Tried to use lazy loading - the same.

It is exactly necessary for me that, in the presence of a file, it would be selected along with the news, and in its absence, only the news would be selected.

FinByPk method:

 public function findByPk($pk,$condition='',$params=array()) { Yii::trace(get_class($this).'.findByPk()','system.db.ar.CActiveRecord'); $prefix=$this->getTableAlias(true).'.'; $criteria=$this->getCommandBuilder()->createPkCriteria($this->getTableSchema(),$pk,$condition,$params,$prefix); return $this->query($criteria); } 
  • Will you show the prototype of the findByPk () function? - Naumov
  • findByPk is the built-in method CActiveRecord - Jeque
  • Clearly an error inside a function. Those. It is necessary to look at the versions of the library where the error is fixed and update to the version without error. Or redefine and fix it yourself. - Naumov
  • Here are the insights of findByPk if it helps: public function findByPk($pk,$condition='',$params=array()) { Yii::trace(get_class($this).'.findByPk()','system.db.ar.CActiveRecord'); $prefix=$this->getTableAlias(true).'.'; $criteria=$this->getCommandBuilder()->createPkCriteria($this->getTableSchema(),$pk,$condition,$params,$prefix); return $this->query($criteria); } public function findByPk($pk,$condition='',$params=array()) { Yii::trace(get_class($this).'.findByPk()','system.db.ar.CActiveRecord'); $prefix=$this->getTableAlias(true).'.'; $criteria=$this->getCommandBuilder()->createPkCriteria($this->getTableSchema(),$pk,$condition,$params,$prefix); return $this->query($criteria); } public function findByPk($pk,$condition='',$params=array()) { Yii::trace(get_class($this).'.findByPk()','system.db.ar.CActiveRecord'); $prefix=$this->getTableAlias(true).'.'; $criteria=$this->getCommandBuilder()->createPkCriteria($this->getTableSchema(),$pk,$condition,$params,$prefix); return $this->query($criteria); } . Only I do not know what exactly is not working correctly - Jeque
  • Write in a question to read hard - Naumov

1 answer 1

In the view there was an appeal to $ model-> files