<commit_before><?php
namespace Anavel\Crud\Abstractor\Eloquent\Relation;

use Anavel\Crud\Abstractor\Eloquent\Relation\Traits\CheckRelationConfig;
use Anavel\Crud\Contracts\Abstractor\Model as ModelAbstractor;
use Anavel\Crud\Contracts\Abstractor\Relation as RelationAbstractorContract;
use ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation as EloquentRelation;
use Anavel\Crud\Contracts\Abstractor\FieldFactory;

abstract class Relation implements RelationAbstractorContract
{
    use CheckRelationConfig;

    protected $name;
    protected $presentation;
    protected $type;
    /**
     * @var Model
     */
    protected $relatedModel;
    /**
     * @var EloquentRelation
     */
    protected $eloquentRelation;
    /**
     * @var FieldFactory
     */
    protected $fieldFactory;
    protected $modelManager;
    /** @var  ModelAbstractor */
    protected $modelAbstractor;
    /**
     * @var array
     */
    protected $config;

    public function __construct(array $config, ModelManager $modelManager, Model $model, EloquentRelation $eloquentRelation, FieldFactory $fieldFactory)
    {
        $this->checkNameConfig($config);
        $this->name = $config['name'];
        $this->relatedModel = $model;
        $this->eloquentRelation = $eloquentRelation;
        $this->fieldFactory = $fieldFactory;

        $this->modelManager = $modelManager;

        $this->config = $config;
        $this->setup();

        $this->modelAbstractor = \App::make('Anavel\Crud\Contracts\Abstractor\ModelFactory')->getByClassName(get_class($this->eloquentRelation->getRelated()), $this->config);
    }

    public function addSecondaryRelationFields(array $fields)
    {
        foreach ($this->modelAbstractor->getRelations() as $relation) {
            foreach ($relation->getEditFields() as $editField) {
                $fields[] = $editField;
            };
        }
        return $fields;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getPresentation()
    {
        return $this->presentation ? : ucfirst(str_replace('_', ' ', $this->name));
    }

    public function getType()
    {
        return get_class($this);
    }
}
<commit_msg>Relation name added to secondary relation fields #5<commit_after><?php
namespace Anavel\Crud\Abstractor\Eloquent\Relation;

use Anavel\Crud\Abstractor\Eloquent\Relation\Traits\CheckRelationConfig;
use Anavel\Crud\Contracts\Abstractor\Model as ModelAbstractor;
use Anavel\Crud\Contracts\Abstractor\Relation as RelationAbstractorContract;
use ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation as EloquentRelation;
use Anavel\Crud\Contracts\Abstractor\FieldFactory;

abstract class Relation implements RelationAbstractorContract
{
    use CheckRelationConfig;

    protected $name;
    protected $presentation;
    protected $type;
    /**
     * @var Model
     */
    protected $relatedModel;
    /**
     * @var EloquentRelation
     */
    protected $eloquentRelation;
    /**
     * @var FieldFactory
     */
    protected $fieldFactory;
    protected $modelManager;
    /** @var  ModelAbstractor */
    protected $modelAbstractor;
    /**
     * @var array
     */
    protected $config;

    public function __construct(array $config, ModelManager $modelManager, Model $model, EloquentRelation $eloquentRelation, FieldFactory $fieldFactory)
    {
        $this->checkNameConfig($config);
        $this->name = $config['name'];
        $this->relatedModel = $model;
        $this->eloquentRelation = $eloquentRelation;
        $this->fieldFactory = $fieldFactory;

        $this->modelManager = $modelManager;

        $this->config = $config;
        $this->setup();

        $this->modelAbstractor = \App::make('Anavel\Crud\Contracts\Abstractor\ModelFactory')->getByClassName(get_class($this->eloquentRelation->getRelated()), $this->config);
    }

    public function addSecondaryRelationFields(array $fields)
    {
        foreach ($this->modelAbstractor->getRelations() as $relation) {
            foreach ($relation->getEditFields() as $editField) {
                $fields[$this->name][] = $editField;
            };
        }
        return $fields;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getPresentation()
    {
        return $this->presentation ? : ucfirst(str_replace('_', ' ', $this->name));
    }

    public function getType()
    {
        return get_class($this);
    }
}

{'fraction_non_alphanumeric': 0.11971679897017808, 'fraction_numerical': 0.00021454623471358077, 'mean_word_length': 3.1147396293027363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2757864', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1368, 'n_words': 247}