Retrieve the MetaModel attached to the model filter setting.

@param ModelInterface $model The model for which to retrieve the MetaModel.

@return IMetaModel

@throws \RuntimeException When the MetaModel can not be determined.
359563
protected function getMetaModel(ModelInterface $model)
    {
        $filterSetting = $this->filterSettingFactory->createCollection($model->getProperty('fid'));

        return $filterSetting->getMetaModel();
    }
316419
protected function fetchModel(EnvironmentInterface $environment, ModelIdInterface $modelId)
    {
        $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        if (!$model || !$model->getId()) {
            throw new DcGeneralRuntimeException(
                'Could not load model with id ' . $modelId->getSerialized()
            );
        }

        return $model;
    }
1151125
protected function propertyFactory()
    {
        if ($this->propertyFactory === null) {
            throw new RuntimeException(sprintf(
                'Model [%s] does not have a property factory.',
                get_class($this)
            ));
        }

        return $this->propertyFactory;
    }
260223
public function remove(ModelInterface $model): RepositoryInterface
    {
        $id = $model->getId();
        $table = $this->getTable();

        if (null === $this->find($id)) {
            return $this;
        }

        $this->connection->beginTransaction();

        $row = $model->toPersistence();

        foreach ($row as $field => $value) {
            if ($value instanceof ModelCollectionInterface) {
                $this->removeRelatedModels($value->getInitialModels());
            } elseif ($value instanceof ModelReferenceInterface) {
                if (null !== $initialModel = $value->getInitialModel()) {
                    $this->removeRelatedModel($initialModel);
                }
            }
        }

        $this->logger->info(
            'model: remove row from table {table} with id {id}',
            ['table' => $table, 'id' => $id]
        );

        $this->connection->delete($table, ['id' => $id]);

        $this->storageCache->remove($id);

        $this->connection->commit();

        return $this;
    }
1006027
protected static function modelEntityType($model)
    {
        if ($model instanceof QuestionInterface) {
            return self::ENTITY_QUESTION;
        } elseif ($model instanceof AnswerInterface) {
            return self::ENTITY_ANSWER;
        } else {
            $className = get_class($model);
            throw new UnknownClassException("Model class '{$className}' not supported");
        }
    }
1081700
public function setModel($model)
	{
		$this->model = $model;
		
		$this->from($this->model->metableTable() . ' AS m');
		
		if ($this->model->metableTableSoftDeletes()) {
			$this->whereNull('m.' . $this->model->getDeletedAtColumn());
		}
		
		return $this;
	}
310550
protected function getModelTable($model)
    {
        if (!is_object($model)) {
            $model = new $model;
        }

        return DB::getTablePrefix().$model->getTable();
    }
191116
protected function modelOrFind($idOrModel)
    {
    	if ($idOrModel instanceof Model && $idOrModel->exists()) {
    		return $idOrModel;
    	}

    	return $this->getModel()->findOrFail($idOrModel);
    }
1131267
public function getColumnMaps(ModelInterface $model, DiInterface $di)
    {
        $reflection = $di['annotations']->get($model);
        $columnMap = array();
        $reverseColumnMap = array();
        $renamed = false;
        foreach ($reflection->getPropertiesAnnotations() as $name => $collection) {
            if ($collection->has('Column')) {
                $arguments = $collection->get('Column')->getArguments();
                /**
                 * Get the column's name
                 */
                if (isset($arguments['column'])) {
                    $columnName = $arguments['column'];
                } else {
                    $columnName = $name;
                }
                $columnMap[$columnName] = $name;
                $reverseColumnMap[$name] = $columnName;
                if (!$renamed) {
                    if ($columnName != $name) {
                        $renamed = true;
                    }
                }
            }
        }
        return array(
            MetaData::MODELS_COLUMN_MAP => $columnMap,
            MetaData::MODELS_REVERSE_COLUMN_MAP => $reverseColumnMap
        );
    }
702775
protected function resolveQueryBuilderFromModel($model)
    {
        if ($this->isEloquentModel($model)) {
            return $model->newQuery();
        } elseif ($this->isEloquentRelationModel($model)) {
            return $model->getQuery();
        } elseif (! $this->isQueryBuilder($model)) {
            throw new InvalidArgumentException('Unable to load Query Builder from $model');
        }

        return $model;
    }
1341643
public function getViewUrl($model = null)
    {
        if (!$model instanceof Mage_Core_Model_Abstract) {
            $model = $this->getCurrentRecord();
        } else {
            $expectedClass = get_class($this->getModel());
            if (!is_a($model, $expectedClass)) {
                throw new RuntimeException($this->__('Invalid model class. Expected:%1$s Passed:%2$s', $expectedClass, get_class($model)));
            }
        }

        return $this->_getUrl($this->getViewRoute(), ['id' => $model->getId()]);
    }
200327
public function hydrateRelations(AbstractModel $model)
    {
        if (!$this->queryBuilder->fetchCacheData($model)) {
            return $model;
        }
        $reflection = new \ReflectionClass($model);

        foreach ($this->queryBuilder->fetchCacheData($model)['relationList'] as $relation) {
            $injectionModel = new $relation['model']();
            try {
                $property = $reflection->getProperty($relation['target']);
            } catch (\Exception $e) {
                $this->log(ILog::T_ERROR, $e->getMessage());
                continue;
            }

            $property->setAccessible(true);

            /**
             * @todo implement dynamic mappings from doc head
             */
            if (!$this->lazyLoading) {
                $mappingProperty = $reflection->getProperty($relation['mapping_id']);
                $mappingProperty->setAccessible(true);
                $this->findOneBy($injectionModel, ['id' => $mappingProperty->getValue($model)]);
                unset($mappingProperty);
            }
            $property->setValue($model, $injectionModel);
        }

        return $model;
    }
1278368
public function getForm(ModelInterface $formData = null, $method = 'POST')
    {
        if (!$this->crud) {
            throw new RuntimeException(sprintf('You must call "setCrud()" before call this method'));
        }

        $formClass = $this->crud->getForm();

        if (class_exists($formClass)) {
            $formObject = new $formClass();
        } else {
            $formObject = $this->container->get($formClass);
        }

        $builder = $this->formFactory->createBuilder(get_class($formObject));
        $builder->setMethod($method);

        $form = $builder->getForm();
        $form->setData($formData);

        return $form;
    }
224381
protected function getReference(Model $model)
    {
        $reference = $this->getReferenceValue($model);

        return $this->wrapWithLink($reference, $this->getLinkForReferenceModel($model));
    }
1274860
public function register(ModelConfigurationInterface $model)
    {
        $this->setModel($model->getClass(), $model);

        if ($model instanceof Initializable) {
            $model->initialize();
        }

        return $this;
    }
667120
protected function setDataFromModel(ModelInterface $model): void
    {
        $this->container->set('model', $model);
        
        foreach (get_class_methods($model) as $method) {
            if (0 !== strpos($method, 'get')) {
                continue;
            }
            
            $this->data[strtolower(substr($method, 3))] = $model->$method();
        }
    }
1005696
public function prepareForm(ModelInterface $model = null, array $data = null, $useInputFilter = false, $useHydrator = false)
    {
        $argv = compact('model', 'data');
        $argv = $this->prepareEventArguments($argv);
        $this->getEventManager()->trigger(self::EVENT_PRE_PREPARE_FORM, $this, $argv);
        $data = $argv['data'];

        /* @var $form Form */
        $form = $this->getForm(null, $this->formOptions);

        if ($useInputFilter) {
            $form->setInputFilter($this->getInputFilter());
        }

        if ($useHydrator) {
            $form->setHydrator($this->getHydrator());
        }

        if ($model) {
            $form->bind($model);
        }

        if ($data) {
            $form->setData($data);
        }

        $argv = compact('form', 'model', 'data');
        $argv = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_POST_PREPARE_FORM, $this, $argv);

        return $form;
    }