<commit_before><?php

namespace Maghead\Schema\Relationship;

use Magsql\Universal\Syntax\Conditions;
use Maghead\Runtime\Collection;
use LogicException;
use ArrayAccess;
use IteratorAggregate;

class Relationship implements IteratorAggregate, ArrayAccess
{
    const HAS_MANY = 1;
    const HAS_ONE = 2;
    const BELONGS_TO = 3;
    const MANY_TO_MANY = 4;

    /**
     * @var array The stashed data
     */
    public $data = array();

    /**
     * @var string The accessor name
     */
    public $accessor;

    /**
     * @var Conditions The Magsql Condition Syntax Object
     */
    public $where;

    public $orderBy = array();

    public $onUpdate;

    public $onDelete;

    public $usingIndex;

    public function __construct($accessor, array $data = array())
    {
        $this->accessor = $accessor;
        $this->data = $data;
    }

    public function by($column)
    {
        $this->data['self_column'] = $column;

        return $this;
    }

    public function usingIndex($index = true)
    {
        $this->usingIndex = $index;
    }

    public function newForeignSchema()
    {
        $class = $this->data['foreign_schema'];

        return new $class();
    }

    public function newForeignModel()
    {
        $schema = $this->newForeignSchema();
        $modelClass = $schema->getModelClass();

        return new $modelClass();
    }

    public function newForeignCollection()
    {
        $schema = $this->newForeignSchema();
        $collectionClass = $schema->getCollectionClass();

        return new $collectionClass();
    }

    /**
     * Resolve the junction relationship to retrieve foreign collection of the foreign collection.
     *
     * This method is only for many-to-many relationship object.
     *
     * @return Maghead\Runtime\Collection The foreign foreign collection.
     */
    public function newForeignForeignCollection($junctionRelation)
    {<commit_msg>use schema loader<commit_after><?php

namespace Maghead\Schema\Relationship;

use Magsql\Universal\Syntax\Conditions;
use Maghead\Schema\SchemaLoader;
use Maghead\Runtime\Collection;
use LogicException;
use ArrayAccess;
use IteratorAggregate;
use ArrayObject;

class Relationship implements IteratorAggregate, ArrayAccess
{
    const HAS_MANY = 1;
    const HAS_ONE = 2;
    const BELONGS_TO = 3;
    const MANY_TO_MANY = 4;

    /**
     * @var array The stashed data
     */
    public $data = array();

    /**
     * @var string The accessor name
     */
    public $accessor;

    /**
     * @var Conditions The Magsql Condition Syntax Object
     */
    public $where;

    public $orderBy = array();

    public $onUpdate;

    public $onDelete;

    public $usingIndex;

    public function __construct($accessor, array $data = array())
    {
        $this->accessor = $accessor;
        $this->data = $data;
    }

    public function by($column)
    {
        $this->data['self_column'] = $column;

        return $this;
    }

    public function usingIndex($index = true)
    {
        $this->usingIndex = $index;
    }

    public function newForeignSchema()
    {
        return SchemaLoader::load($this->data['foreign_schema']);
    }

    public function newForeignModel()
    {
        $schema = $this->newForeignSchema();
        $modelClass = $schema->getModelClass();

        return new $modelClass();
    }

    public function newForeignCollection()
    {
        $schema = $this->newForeignSchema();
        $collectionClass = $schema->getCollectionClass();

        return new $collectionClass();
    }

    /**
     * Resolve the junction relationship to retrieve foreign collection of the foreign collection.
     *
     * This method is only for many-to-many relationship object.
     *
     * @return Maghead\Runtime\Collection The foreign foreign collection.
     */
    public function newForeignForeignCollection($junctionRelation)
    {
{'fraction_non_alphanumeric': 0.10728952772073921, 'fraction_numerical': 0.002053388090349076, 'mean_word_length': 2.588397790055249, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '118985', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1084, 'n_words': 289}