<commit_before>
namespace Ice\Mvc;

use Ice\Di;
use Ice\Arr;
use Ice\Exception;
use Ice\Validation;

/**
 * Model connects business objects and database tables to create a persistable domain model where logic and data are
 * presented in one wrapping (ORM & ODM).
 *
 * @package     Ice/Db
 * @category    Component
 * @author      Ice Team
 * @copyright   (c) 2014-2018 Ice Team
 * @license     http://iceframework.org/license
 */
abstract class Model extends Arr implements \Serializable
{

    protected di { get };
    protected db { get };
    protected service = "db";
    protected from { set };
    protected primary { set, get };
    protected autoincrement = true { set };
    protected filters = [] { set, get };
    protected fields = [] { set, get };
    protected validation { set, get };
    protected relations = [] { get };
    protected labels = [] { set };
    protected rules = [];
    protected messages = [] { get, set };

    // this model has been loaded from service
    protected isLoaded = null;

    const BELONGS_TO = 1;
    const HAS_ONE = 2;
    const HAS_MANY = 3;

    /**
     * Model constructor. Fetch Di and set it as a property.
     *
     * @param mixed filters
     * @param array data
     * @param array options Options to limit/group/orderby results when filters is not null
     */
    public function __construct(var filters = null, array data = [], array options = [])
    {
        var di;

        let di = Di::$fetch(),
            this->di = di,
            this->db = di->get(this->service);

        let data = array_merge(array_fill_keys(this->fields, null), data);

        parent::__construct(data);

        if !this->from {
            let this->from = uncamelize(get_class_ns(this));
        }

        if !this->primary {
            let this->primary = this->db->getId();
        }

        if method_exists(this, "onConstruct") {
            this->{"onConstruct"}();
        }

        if filters {
            this->loadOne(filters, options);
        }

        if method_exists(this, "initialize") {
            this->{"initialize"}();
        }
    }

    /**
     * Get the id.
     *
     * @return mixed
     */
    public function getId()
    {
        return this->get(this->getIdKey());
    }

    /**
     * Get the id key depending on db driver.
     *
     * @return string
     */<commit_msg>Model, get id fix #240<commit_after>
namespace Ice\Mvc;

use Ice\Di;
use Ice\Arr;
use Ice\Exception;
use Ice\Validation;

/**
 * Model connects business objects and database tables to create a persistable domain model where logic and data are
 * presented in one wrapping (ORM & ODM).
 *
 * @package     Ice/Db
 * @category    Component
 * @author      Ice Team
 * @copyright   (c) 2014-2018 Ice Team
 * @license     http://iceframework.org/license
 */
abstract class Model extends Arr implements \Serializable
{

    protected di { get };
    protected db { get };
    protected service = "db";
    protected from { set };
    protected primary { set, get };
    protected autoincrement = true { set };
    protected filters = [] { set, get };
    protected fields = [] { set, get };
    protected validation { set, get };
    protected relations = [] { get };
    protected labels = [] { set };
    protected rules = [];
    protected messages = [] { get, set };

    // this model has been loaded from service
    protected isLoaded = null;

    const BELONGS_TO = 1;
    const HAS_ONE = 2;
    const HAS_MANY = 3;

    /**
     * Model constructor. Fetch Di and set it as a property.
     *
     * @param mixed filters
     * @param array data
     * @param array options Options to limit/group/orderby results when filters is not null
     */
    public function __construct(var filters = null, array data = [], array options = [])
    {
        var di;

        let di = Di::$fetch(),
            this->di = di,
            this->db = di->get(this->service);

        let data = array_merge(array_fill_keys(this->fields, null), data);

        parent::__construct(data);

        if !this->from {
            let this->from = uncamelize(get_class_ns(this));
        }

        if !this->primary {
            let this->primary = this->db->getId();
        }

        if method_exists(this, "onConstruct") {
            this->{"onConstruct"}();
        }

        if filters {
            this->loadOne(filters, options);
        }

        if method_exists(this, "initialize") {
            this->{"initialize"}();
        }
    }

    /**
     * Get the id.
     *
     * @return mixed
     */
    public function getId()
    {
        if typeof this->primary == "array" {
            return this->only(this->primary);
        } else {
            return this->get(this->primary);
        }
    }

    /**
     * Get the id key depending on db driver.
     *
     * @return string
     */
{'fraction_non_alphanumeric': 0.12114356232003291, 'fraction_numerical': 0.005141916906622789, 'mean_word_length': 2.013011152416357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '5854790', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1351, 'n_words': 437}