Return first meta model by parent id and meta name.

@param integer $modelId Parent Id.
@param string $name
@return ModelMeta|array|null by parent id and meta name.
971093
public static function findFirstByName( $modelId, $name ) {

		$query	= self::queryByName( $modelId, $name );

		return $query->one();
	}
1373834
public function meta($key = null)
    {
        if (isset($key)) {
            return $this->model->findMeta($this->id, $key);
        }

        return $this->model->getMeta($this->id);
    }
162543
protected function loadModel($id = null)
	{
		/** @var BaseActiveRecord $modelClass */
		$modelClass = $this->modelClass();
		if($id) {
			$this->modelInstance = $modelClass::findOne($id);
		} else {
			$this->modelInstance = new $modelClass();
		}
		$this->modelInstance->load($this->attributes, '');
		return $this->modelInstance;
	}
692825
private function modelIs($conjunction, ModelId $modelId)
    {
        if (!empty($this->expression)) {
            $this->expression[] = $conjunction;
        }

        $index              = \count($this->variables);
        $this->expression[] = \sprintf(self::MODEL_IS_EXPRESSION, $index);
        $this->variables[]  = $modelId;
        $this->compiled     = null;

        return $this;
    }
882238
public function findOne(string $name, string $resourceId): Model
    {
        return $this->getRepository($name)
            ->query()
            ->setResourceId($resourceId)
            ->findOne();
    }
1148019
public function getDelete($modelitemId)
    {
        if (!$this->modelAdmin->hasDeleting()) {
            return $this->missingMethod();
        }

        if ($this->modelAdmin->hasSoftDeleting()) {
            $this->modelAdmin->findWithTrashed($modelitemId);
        } else {
            $this->modelAdmin->find($modelitemId);
        }

        return view('flare::admin.modeladmin.delete', ['modelItem' => $this->modelAdmin->model]);
    }
338958
public function getByParent( $parentId, $parentType, $config = [] ) {

		$modelClass	= static::$modelClass;

		return $modelClass::findByParent( $parentId, $parentType, $config );
	}
478189
public function findById($name, $id) {
        $this->load();
        $mapper = MapperBuilder::buildFromName($this->mapping, $name);

        $newEntity = NULL;

        $query = "SELECT * FROM `" . $mapper->getTable() . "` WHERE id = :id";

        $result = $this->getDataSource()->query($query, array(":id" => $id));

        if ($result) {
            $newEntity = $mapper->createObject($result[0]);

            /* relations */
            foreach ($mapper->getRelations() as $relation) {

                /* only set relations if not lazy */
                if (!$relation->isLazy()) {
                    $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());

                    $queryRel = QueryBuilder::buildSelectRelation($relation, $relMapper);

                    $resRel = $this->getDataSource()->query($queryRel, array(":id" => $newEntity->getId()));

                    $method = "set" . $relation->getName();
                    if ($resRel) {
                        $collection = new Collection($relMapper->getClass(), $resRel, $relMapper);
                    } else {
                        $collection = new Collection($relMapper->getClass(), array(), $relMapper);
                    }
                    $newEntity->$method($collection);
                }
            }
        }
        return $newEntity;
    }
1279590
public static function isExistByNameType( $modelId, $name, $type ) {

		$meta = self::findByNameType( $modelId, $type, $name );

		return isset( $meta );
	}
7363
public function customModelItemAction($modelName, $id = null)
    {
        $config        = app('itemconfig');
        $actionFactory = app('admin_action_factory');
        $model         = $config->getDataModel();
        $model         = $model::find($id);
        $actionName    = $this->request->input('action_name', false);

        //get the action and perform the custom action
        $action = $actionFactory->getByName($actionName);
        $result = $action->perform($model);

        //override the config options so that we can get the latest
        app('admin_config_factory')->updateConfigOptions();

        //if the result is a string, return that as an error.
        if (is_string($result)) {
            return response()->json(array('success' => false, 'error' => $result));
        }
        //if it's falsy, return the standard error message
        elseif (!$result) {
            $messages = $action->getOption('messages');

            return response()->json(array('success' => false, 'error' => $messages['error']));
        } else {
            $fieldFactory  = app('admin_field_factory');
            $columnFactory = app('admin_column_factory');
            $fields        = $fieldFactory->getEditFields();
            $model         = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields));

            if ($model->exists) {
                $model = $config->updateModel($model, $fieldFactory, $actionFactory);
            }

            $response = array('success' => true, 'data' => $model->toArray());

            //if it's a download response, flash the response to the session and return the download link
            if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) {
                $file    = $result->getFile()->getRealPath();
                $headers = $result->headers->all();
                $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers));

                $response['download'] = route('admin_file_download');
            }
            //if it's a redirect, put the url into the redirect key so that javascript can transfer the user
            elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) {
                $response['redirect'] = $result->getTargetUrl();
            }

            return response()->json($response);
        }
    }
673170
public function fetchModelFromProvider($modelId, $providerName = null)
    {
        // @codingStandardsIgnoreStart
        @\trigger_error(
            'Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::getModel()',
            E_USER_DEPRECATED
        );
        // @codingStandardsIgnoreEnd

        return $this->modelCollector->getModel($modelId, $providerName);
    }
583576
public function getModel($name) {
        if(!isset($this->models[$name])){
            throw new RuntimeException(sprintf("The model document name '%s' is not added in chain model '%s'",$name,$this->id));
        }
        $this->models[$name]->setContainer($this->container);
        return $this->models[$name];
    }
600801
public function getMetadata(string $name)
    {
        return $this->metadata->where(function (ContentMetadata $metadata) use ($name) {
            return $metadata->name === $name;
        })->first();
    }
1172745
public function findModel($model_name, $id = null)
    {
        $model = config('kregel.warden.models.'.$model_name.'.model');
        if (empty($id) | !is_numeric($id)) {
            return new $model();
        }

        return $model::find($id);
    }
1132301
public function deleteById(string $modelId)
    {
        $deleteResult = $this->getRequest()->request(
            'DELETE',
            $this->getRequestUrl(sprintf('models/%s', $modelId))
        );

        return $deleteResult['status'];
    }
878757
public function find(Driver $driver, $modelClass, $id)
    {
        $this->managerFactory->setModelClass($modelClass);

        return $this->managerFactory->getManager($driver)->find($id);
    }
859403
public static function queryByParentModelId( $parentId, $parentType, $modelId ) {

		$tableName = static::tableName();

		return self::queryWithModel()->where( "$tableName.parentId=:pid AND $tableName.parentType=:ptype AND $tableName.modelId=:mid", [ ':pid' => $parentId, ':ptype' => $parentType, ':mid' => $modelId ] );
	}