Example #1
0
 protected function onAfterInsertInternal()
 {
     $meta = static::getMeta();
     foreach ($this->getFieldsInit() as $name => $field) {
         if ($this->getPkName() == $name || $meta->hasHasManyField($name) || $meta->hasManyToManyField($name) || $meta->hasOneToOneField($name)) {
             continue;
         } else {
             if ($meta->hasForeignField($name)) {
                 $foreighField = $meta->getForeignField($name);
                 $name .= "_" . MetaData::getInstance($foreighField->modelClass)->getPkName();
             }
         }
         $field->setModel($this);
         $field->setValue($this->getAttribute($name));
         $field->onAfterInsert();
     }
     $signal = $this->getEventManager();
     $signal->send($this, 'afterSave', $this, true);
 }
 /**
  * @return array "link" table columns
  */
 public function getColumns()
 {
     if (!$this->through) {
         $fields = $this->getRelatedModel()->getFieldsInit();
         $this->addColumn($this->getRelatedModelColumn(), $fields[$this->getRelatedModelPk()]->sqlType());
         $fields = MetaData::getInstance($this->ownerClassName)->getFieldsInit($this->ownerClassName);
         $this->addColumn($this->getModelColumn(), $fields[$this->getModelPk()]->sqlType());
     }
     return $this->_columns;
 }