Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function formField($kwargs = [])
 {
     if ($this->relation->parentLink) {
         return;
     }
     return parent::formField($kwargs);
 }
Exemplo n.º 2
0
 /**
  * @ignore
  *
  * @param array $opts
  *
  * @return ForeignKey
  */
 public static function ForeignKey($opts = [])
 {
     return ForeignKey::createObject($opts);
 }
Exemplo n.º 3
0
 /**
  * Creates an intermediary model.
  *
  * @param ManyToManyField $field
  * @param Model           $model
  *
  * @return Model
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function createManyToManyIntermediaryModel($field, $model)
 {
     $modelName = $model->meta->modelName;
     if (is_string($field->relation->toModel)) {
         $toModelName = Tools::resolveRelation($model, $field->relation->toModel);
     } else {
         $toModelName = $field->relation->toModel->meta->modelName;
     }
     $className = sprintf('%1$s_%2$s', $modelName, $field->name);
     $intermediaryClass = 'class %1$s extends %2$s{
         public function fields(){}
     }';
     $intermediaryClass = sprintf($intermediaryClass, $className, Model::getFullClassName());
     if (!class_exists($className, false)) {
         eval($intermediaryClass);
     }
     $from = strtolower($modelName);
     $to = strtolower($toModelName);
     if ($from == $to) {
         $to = sprintf('to_%s', $to);
         $from = sprintf('from_%s', $from);
     }
     $fields = [$from => ForeignKey::createObject(['to' => $modelName, 'dbConstraint' => $field->relation->dbConstraint, 'onDelete' => Delete::CASCADE]), $to => ForeignKey::createObject(['to' => $toModelName, 'dbConstraint' => $field->relation->dbConstraint, 'onDelete' => Delete::CASCADE])];
     $meta = ['dbTable' => $field->_getM2MDbTable($model->meta), 'verboseName' => sprintf('%s-%s relationship', $from, $to), 'uniqueTogether' => [$from, $to], 'autoCreated' => true];
     $className = '\\' . $className;
     /** @var $intermediaryObj Model */
     $intermediaryObj = new $className();
     $intermediaryObj->init($fields, ['meta' => $meta, 'registry' => $field->scopeModel->meta->registry]);
     return $intermediaryObj;
 }