public function materialize(array $data, $instance)
    {
        if (empty($data)) {
            return;
        }

        if (!$this->isMaterializable($data)) {
            throw new AnDomainExceptionMapping($this->getName().' Mapping Failed');
        }

        $child_key = $this->_child_column->key();

        //get parent value
        $parent_value = $data[$child_key];

        //get parent class identifier
        //if relationsip is polymorphic then get the type from
        //the data
        if ($this->_polymorphic) {
            $key = $this->_type_column->key();
            $parent = isset($data[$key]) ? $data[$key] : null;
            if ($parent) {
                $parent = AnService::getIdentifier($parent);
                if (!$parent->application) {
                    $parent->application = $this->_child->application;
                }
            }
        } else {
            $parent = $this->_parent;
        }

        //if any of the parent and parent value is missing then
        //nullify the relationship
        if (empty($parent) || empty($parent_value)) {
            return;
        }

        $config = array();

        $config['relationship'] = $this;
        $config['value'] = $parent_value;
        $config['property'] = $this->_parent_key;
        $config['service_identifier'] = AnDomain::getRepository($parent)
                    ->getDescription()->getEntityIdentifier();

        return new AnDomainEntityProxy(new AnConfig($config));
    }
public function materialize(array $data, $instance)
    {
        if (empty($data)) {
            return;
        }

        if (!$this->isMaterializable($data)) {
            throw new AnDomainExceptionMapping($this->getName().' Mapping Failed');
        }

        $child_key = $this->_child_column->key();

        //get parent value
        $parent_value = $data[$child_key];

        //get parent class identifier
        //if relationsip is polymorphic then get the type from
        //the data
        if ($this->_polymorphic) {
            $key = $this->_type_column->key();
            $parent = isset($data[$key]) ? $data[$key] : null;
            if ($parent) {
                $parent = AnService::getIdentifier($parent);
                if (!$parent->application) {
                    $parent->application = $this->_child->application;
                }
            }
        } else {
            $parent = $this->_parent;
        }

        //if any of the parent and parent value is missing then
        //nullify the relationship
        if (empty($parent) || empty($parent_value)) {
            return;
        }

        $config = array();

        $config['relationship'] = $this;
        $config['value'] = $parent_value;
        $config['property'] = $this->_parent_key;
        $config['service_identifier'] = AnDomain::getRepository($parent)
                    ->getDescription()->getEntityIdentifier();

        return new AnDomainEntityProxy(new AnConfig($config));
    }
public function materialize ( array $ data , $ instance ) { if ( empty ( $ data ) ) { return ; } if ( ! $ this -> isMaterializable ( $ data ) ) { throw new AnDomainExceptionMapping ( $ this -> getName ( ) . ' Mapping Failed' ) ; } $ child_key = $ this -> _child_column -> key ( ) ; //get parent value $ parent_value = $ data [ $ child_key ] ; //get parent class identifier //if relationsip is polymorphic then get the type from //the data if ( $ this -> _polymorphic ) { $ key = $ this -> _type_column -> key ( ) ; $ parent = isset ( $ data [ $ key ] ) ? $ data [ $ key ] : null ; if ( $ parent ) { $ parent = AnService :: getIdentifier ( $ parent ) ; if ( ! $ parent -> application ) { $ parent -> application = $ this -> _child -> application ; } } } else { $ parent = $ this -> _parent ; } //if any of the parent and parent value is missing then //nullify the relationship if ( empty ( $ parent ) || empty ( $ parent_value ) ) { return ; } $ config = array ( ) ; $ config [ 'relationship' ] = $ this ; $ config [ 'value' ] = $ parent_value ; $ config [ 'property' ] = $ this -> _parent_key ; $ config [ 'service_identifier' ] = AnDomain :: getRepository ( $ parent ) -> getDescription ( ) -> getEntityIdentifier ( ) ; return new AnDomainEntityProxy ( new AnConfig ( $ config ) ) ; }
Materialize a many-to-one relationship for the entity and the data from
the database.

@param AnDomainEntityAbstract $instance The entity whose relationship it's materializing for
@param array                  $data     The row data

@return AnDomainProxyEntity
Materialize a many - to - one relationship for the entity and the data from the database .