library/Garp/Spawn/Relation.php
public function getRules($subjectModel) {
        if ($this->type === 'hasMany') {
            return array($this->oppositeRule);
        }
        if ($this->type === 'hasAndBelongsToMany') {
            $bindingModel = $this->getBindingModel();
            $relations = $bindingModel->relations->getRelations();
            $rules = array_keys($relations);

            /* 	Now sort egocentrically, because current sorting is alphabetical
            (since $relations is an associative array) */
            $firstRel = current($relations);
            if ($firstRel->model !== $subjectModel) {
                $rules = array_reverse($rules);
            }

            if ($this->isHomo()
                && ($rules[0] !== $subjectModel && $rules[1] === $subjectModel)
            ) {
                // Make sure that the custom named relation always comes second.
                // This is part of egocentrism.
                $rules = array_reverse($rules);
            }
            return $rules;
        }
        return array($this->name);
    }
public function getRules($subjectModel) {
        if ($this->type === 'hasMany') {
            return array($this->oppositeRule);
        }
        if ($this->type === 'hasAndBelongsToMany') {
            $bindingModel = $this->getBindingModel();
            $relations = $bindingModel->relations->getRelations();
            $rules = array_keys($relations);

            /* 	Now sort egocentrically, because current sorting is alphabetical
            (since $relations is an associative array) */
            $firstRel = current($relations);
            if ($firstRel->model !== $subjectModel) {
                $rules = array_reverse($rules);
            }

            if ($this->isHomo()
                && ($rules[0] !== $subjectModel && $rules[1] === $subjectModel)
            ) {
                // Make sure that the custom named relation always comes second.
                // This is part of egocentrism.
                $rules = array_reverse($rules);
            }
            return $rules;
        }
        return array($this->name);
    }
public function getRules ( $ subjectModel ) { if ( $ this -> type === 'hasMany' ) { return array ( $ this -> oppositeRule ) ; } if ( $ this -> type === 'hasAndBelongsToMany' ) { $ bindingModel = $ this -> getBindingModel ( ) ; $ relations = $ bindingModel -> relations -> getRelations ( ) ; $ rules = array_keys ( $ relations ) ; /* 	Now sort egocentrically, because current sorting is alphabetical
            (since $relations is an associative array) */ $ firstRel = current ( $ relations ) ; if ( $ firstRel -> model !== $ subjectModel ) { $ rules = array_reverse ( $ rules ) ; } if ( $ this -> isHomo ( ) && ( $ rules [ 0 ] !== $ subjectModel && $ rules [ 1 ] === $ subjectModel ) ) { // Make sure that the custom named relation always comes second. // This is part of egocentrism. $ rules = array_reverse ( $ rules ) ; } return $ rules ; } return array ( $ this -> name ) ; }
Return the rules that make up this relation, as used in the referenceMap.

@param string $subjectModel Name of the model you're viewing from. Determines the direction
in some cases.
@return array In case of 'hasMany', an array containing a single rule, in case of
'hasAndBelongsToMany', an array containing two rules referencing two models.
Return the rules that make up this relation as used in the referenceMap .