private function _resolveBelongsTo($attr, $values)
    {
        $cls = get_called_class();
        if (!array_key_exists($cls, self::$_belongs_to)
            || !array_key_exists($attr, self::$_belongs_to[$cls])
        ) {
            return null;
        }

        $configs       = self::$_belongs_to[$cls][$attr];
        $belongs_cls   = is_array($configs) && array_key_exists("class_name",  $configs) ? $configs["class_name"]  : ucfirst($attr);
        $belongs_key   = is_array($configs) && array_key_exists("foreign_key", $configs) ? $configs["foreign_key"] : strtolower($belongs_cls)."_id";
        $primary_key   = is_array($configs) && array_key_exists("primary_key", $configs) ? $configs["primary_key"] : "id";
        $value         = $values[$belongs_key];

        if (array_key_exists($attr, $this->_belongs_cache) && $this->_belongs_cache[$attr] && $this->_belongs_cache[$attr]->$primary_key == $value) {
            return $this->_belongs_cache[$attr];
        }

        $obj = $belongs_cls::first(array($primary_key => $value));

        if ($obj) {
            $this->_belongs_cache[$attr] = $obj;
        }
        return $obj;
    }
private function _resolveBelongsTo($attr, $values)
    {
        $cls = get_called_class();
        if (!array_key_exists($cls, self::$_belongs_to)
            || !array_key_exists($attr, self::$_belongs_to[$cls])
        ) {
            return null;
        }

        $configs       = self::$_belongs_to[$cls][$attr];
        $belongs_cls   = is_array($configs) && array_key_exists("class_name",  $configs) ? $configs["class_name"]  : ucfirst($attr);
        $belongs_key   = is_array($configs) && array_key_exists("foreign_key", $configs) ? $configs["foreign_key"] : strtolower($belongs_cls)."_id";
        $primary_key   = is_array($configs) && array_key_exists("primary_key", $configs) ? $configs["primary_key"] : "id";
        $value         = $values[$belongs_key];

        if (array_key_exists($attr, $this->_belongs_cache) && $this->_belongs_cache[$attr] && $this->_belongs_cache[$attr]->$primary_key == $value) {
            return $this->_belongs_cache[$attr];
        }

        $obj = $belongs_cls::first(array($primary_key => $value));

        if ($obj) {
            $this->_belongs_cache[$attr] = $obj;
        }
        return $obj;
    }
private function _resolveBelongsTo ( $ attr , $ values ) { $ cls = get_called_class ( ) ; if ( ! array_key_exists ( $ cls , self :: $ _belongs_to ) || ! array_key_exists ( $ attr , self :: $ _belongs_to [ $ cls ] ) ) { return null ; } $ configs = self :: $ _belongs_to [ $ cls ] [ $ attr ] ; $ belongs_cls = is_array ( $ configs ) && array_key_exists ( "class_name" , $ configs ) ? $ configs [ "class_name" ] : ucfirst ( $ attr ) ; $ belongs_key = is_array ( $ configs ) && array_key_exists ( "foreign_key" , $ configs ) ? $ configs [ "foreign_key" ] : strtolower ( $ belongs_cls ) . "_id" ; $ primary_key = is_array ( $ configs ) && array_key_exists ( "primary_key" , $ configs ) ? $ configs [ "primary_key" ] : "id" ; $ value = $ values [ $ belongs_key ] ; if ( array_key_exists ( $ attr , $ this -> _belongs_cache ) && $ this -> _belongs_cache [ $ attr ] && $ this -> _belongs_cache [ $ attr ] -> $ primary_key == $ value ) { return $ this -> _belongs_cache [ $ attr ] ; } $ obj = $ belongs_cls :: first ( array ( $ primary_key => $ value ) ) ; if ( $ obj ) { $ this -> _belongs_cache [ $ attr ] = $ obj ; } return $ obj ; }
Resolve a belongs to association

@param string $attr   attribute
@param mixed  $values values to use

@return association
Resolve a belongs to association