<commit_before><?php
namespace Czim\PxlCms\Models;

use Lookitsatravis\Listify\Listify;
use Watson\Rememberable\Rememberable;

/**
 * Can use Listify out of the box because images uses 'position' column
 */
class Image extends CmsModel
{
    use Listify,
        Rememberable;

    protected $table = 'cms_m_images';

    public $timestamps = false;

    protected $fillable = [
        'file',
        'caption',
        'extension',
    ];

    protected $dates = [
        'uploaded',
    ];

    protected $hidden = [
        'field_id',
        'entry_id',
    ];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->initListify();
    }

}<commit_msg>image model associable to field id<commit_after><?php
namespace Czim\PxlCms\Models;

use Lookitsatravis\Listify\Listify;
use Watson\Rememberable\Rememberable;

/**
 * Can use Listify out of the box because images uses 'position' column
 */
class Image extends CmsModel
{
    use Listify,
        Rememberable;

    protected $table = 'cms_m_images';

    public $timestamps = false;

    /**
     * @var int|null    which field this is associated with, if any
     */
    public $associatedFieldId;


    protected $fillable = [
        'file',
        'caption',
        'extension',
    ];

    protected $dates = [
        'uploaded',
    ];

    protected $hidden = [
        'field_id',
        'entry_id',
    ];

    public function toArray()
    {
        $array = parent::toArray();

        $array['field_id'] = $this->associatedFieldId;

        return $array;
    }

    /**
     * @param array $attributes
     */
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->initListify();
    }

    /**
     * Associate this image with a given fieldId
     * This makes sense when the image is retrieved for a field/relation of a module/model
     * that may have resizes associated with it, for instance.
     *
     * @param int $fieldId
     */
    public function associateWithFieldId($fieldId)
    {
        $this->associatedFieldId = $fieldId;
    }

}
{'fraction_non_alphanumeric': 0.11265646731571627, 'fraction_numerical': 0.0, 'mean_word_length': 2.32, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6471044', 'n_tokens_mistral': 658, 'n_tokens_neox': 631, 'n_words': 167}