public function push($obj)
    {
        if (!$obj) {
            return;
        }

        $cls           = get_called_class();
        $escape        = Driver::$escape_char;
        $value         = array_key_exists(self::getPK(), $this->_data) ? $this->_data[self::getPK()] : null;
        $other_cls     = get_class($obj);
        $other_pk      = $other_cls::getPK();
        $other_value   = $obj->get($other_pk);
        $table         = Model::getTableName($other_cls);
        $foreign       = self::hasManyForeignKey(Inflections::pluralize(strtolower($other_cls)));

        // if the current object exists ...
        if (!is_null($value)) {
            $obj->set(strtolower($foreign), $value);

            // if the pushed object is still not saved
            if (is_null($other_value)) {
                if (!$obj->save()) {
                    return false;
                }
                $other_value = $obj->get($other_pk);
            }

            $foreign    = self::$_mapping[$other_cls][$foreign];
            $other_pk   = self::$_mapping[$other_cls][$other_pk];
            $sql        = "update $escape$table$escape set $escape$foreign$escape=$value where $escape$other_pk$escape=$other_value";
            $stmt       = self::query($sql);
            $rst        = $stmt->rowCount()==1;
            self::closeCursor($stmt);
            return $rst;
        }

        // if current object does not exists ...
        if (is_null($value)) {
            $this->_pushLater($obj);
        }
    }
public function push($obj)
    {
        if (!$obj) {
            return;
        }

        $cls           = get_called_class();
        $escape        = Driver::$escape_char;
        $value         = array_key_exists(self::getPK(), $this->_data) ? $this->_data[self::getPK()] : null;
        $other_cls     = get_class($obj);
        $other_pk      = $other_cls::getPK();
        $other_value   = $obj->get($other_pk);
        $table         = Model::getTableName($other_cls);
        $foreign       = self::hasManyForeignKey(Inflections::pluralize(strtolower($other_cls)));

        // if the current object exists ...
        if (!is_null($value)) {
            $obj->set(strtolower($foreign), $value);

            // if the pushed object is still not saved
            if (is_null($other_value)) {
                if (!$obj->save()) {
                    return false;
                }
                $other_value = $obj->get($other_pk);
            }

            $foreign    = self::$_mapping[$other_cls][$foreign];
            $other_pk   = self::$_mapping[$other_cls][$other_pk];
            $sql        = "update $escape$table$escape set $escape$foreign$escape=$value where $escape$other_pk$escape=$other_value";
            $stmt       = self::query($sql);
            $rst        = $stmt->rowCount()==1;
            self::closeCursor($stmt);
            return $rst;
        }

        // if current object does not exists ...
        if (is_null($value)) {
            $this->_pushLater($obj);
        }
    }
public function push ( $ obj ) { if ( ! $ obj ) { return ; } $ cls = get_called_class ( ) ; $ escape = Driver :: $ escape_char ; $ value = array_key_exists ( self :: getPK ( ) , $ this -> _data ) ? $ this -> _data [ self :: getPK ( ) ] : null ; $ other_cls = get_class ( $ obj ) ; $ other_pk = $ other_cls :: getPK ( ) ; $ other_value = $ obj -> get ( $ other_pk ) ; $ table = Model :: getTableName ( $ other_cls ) ; $ foreign = self :: hasManyForeignKey ( Inflections :: pluralize ( strtolower ( $ other_cls ) ) ) ; // if the current object exists ... if ( ! is_null ( $ value ) ) { $ obj -> set ( strtolower ( $ foreign ) , $ value ) ; // if the pushed object is still not saved if ( is_null ( $ other_value ) ) { if ( ! $ obj -> save ( ) ) { return false ; } $ other_value = $ obj -> get ( $ other_pk ) ; } $ foreign = self :: $ _mapping [ $ other_cls ] [ $ foreign ] ; $ other_pk = self :: $ _mapping [ $ other_cls ] [ $ other_pk ] ; $ sql = "update $escape$table$escape set $escape$foreign$escape=$value where $escape$other_pk$escape=$other_value" ; $ stmt = self :: query ( $ sql ) ; $ rst = $ stmt -> rowCount ( ) == 1 ; self :: closeCursor ( $ stmt ) ; return $ rst ; } // if current object does not exists ... if ( is_null ( $ value ) ) { $ this -> _pushLater ( $ obj ) ; } }
Push an objet to a has many association

@param mixed $obj object

@return pushed
Push an objet to a has many association