protected function loadEmbed($key)
    {
        $attrs = $this->getAttrs();
        $embed = $attrs[$key];
        $cache = &$this->_cache;

        if (isset($this->cleanData[$key])) {
            $value = $this->cleanData[$key];
        } else {
            $value = null;
        }

        $model = $embed['model'];
        $type = $embed['type'];
        if ( isset($cache[$key]) ) {
            $obj = &$cache[$key];

            return $obj;
        } else {
            if (class_exists($model)) {
                if ($type == self::DATA_TYPE_EMBED) {
                    if ($value) {
                        $data = $value;
                        $object = new $model($data);
                        $object->embed = true;
                        $cache[$key] = $object;

                        return $object;
                    }

                    return null;
                } elseif ($type == self::DATA_TYPE_EMBEDS) {
                    $res = array();
                    if (!empty($value)) {
                        foreach ($value as $item) {
                            $data = $item;
                            $record = new $model($data);
                            $record->embed = true;
                            if ($record) {
                                $res[] = $record;
                            }
                        }
                    }
                    $set =  Collection::make($res);
                    $cache[$key] = $set;
                    $obj = &$cache[$key];

                    return $obj;
                }
            }
        }
    }
protected function loadEmbed($key)
    {
        $attrs = $this->getAttrs();
        $embed = $attrs[$key];
        $cache = &$this->_cache;

        if (isset($this->cleanData[$key])) {
            $value = $this->cleanData[$key];
        } else {
            $value = null;
        }

        $model = $embed['model'];
        $type = $embed['type'];
        if ( isset($cache[$key]) ) {
            $obj = &$cache[$key];

            return $obj;
        } else {
            if (class_exists($model)) {
                if ($type == self::DATA_TYPE_EMBED) {
                    if ($value) {
                        $data = $value;
                        $object = new $model($data);
                        $object->embed = true;
                        $cache[$key] = $object;

                        return $object;
                    }

                    return null;
                } elseif ($type == self::DATA_TYPE_EMBEDS) {
                    $res = array();
                    if (!empty($value)) {
                        foreach ($value as $item) {
                            $data = $item;
                            $record = new $model($data);
                            $record->embed = true;
                            if ($record) {
                                $res[] = $record;
                            }
                        }
                    }
                    $set =  Collection::make($res);
                    $cache[$key] = $set;
                    $obj = &$cache[$key];

                    return $obj;
                }
            }
        }
    }
protected function loadEmbed ( $ key ) { $ attrs = $ this -> getAttrs ( ) ; $ embed = $ attrs [ $ key ] ; $ cache = & $ this -> _cache ; if ( isset ( $ this -> cleanData [ $ key ] ) ) { $ value = $ this -> cleanData [ $ key ] ; } else { $ value = null ; } $ model = $ embed [ 'model' ] ; $ type = $ embed [ 'type' ] ; if ( isset ( $ cache [ $ key ] ) ) { $ obj = & $ cache [ $ key ] ; return $ obj ; } else { if ( class_exists ( $ model ) ) { if ( $ type == self :: DATA_TYPE_EMBED ) { if ( $ value ) { $ data = $ value ; $ object = new $ model ( $ data ) ; $ object -> embed = true ; $ cache [ $ key ] = $ object ; return $ object ; } return null ; } elseif ( $ type == self :: DATA_TYPE_EMBEDS ) { $ res = array ( ) ; if ( ! empty ( $ value ) ) { foreach ( $ value as $ item ) { $ data = $ item ; $ record = new $ model ( $ data ) ; $ record -> embed = true ; if ( $ record ) { $ res [ ] = $ record ; } } } $ set = Collection :: make ( $ res ) ; $ cache [ $ key ] = $ set ; $ obj = & $ cache [ $ key ] ; return $ obj ; } } } }
Load the embed attribute

@param string $key key

@return null
Load the embed attribute