<commit_before><?php
class Controller_Data_Mongo extends Controller_Data {
    function setSource($model,$table){

        if(@!$this->api->mongoclient){
            $m=new MongoClient();

            $collection=$this->api->getConfig('mongo/db');


            $this->api->mongoclient=$m->$collection;

        }

        parent::setSource($model,array(
            'db'=>$this->api->mongoclient->$table,
            'conditions'=>array(),
            'collection'=>$model->table
        ));

        //$model->data=$model->_table[$this->short_name]['db']->get($id);
    }

    /** Implemetns access to our private storage inside model */
    public function _get($model,$key){
        return $model->_table[$this->short_name][$key];
    }
    public function _set($model,$key,$val){
        $model->_table[$this->short_name][$key]=$val;
    }

    function save($model,$id=null){

        $data=array();

        foreach($model->elements as $name=>$f)if($f instanceof Field){
            if(!$f->editable() && !$f->system())continue;
            if(!isset($model->dirty[$name]) && $f->defaultValue()===null)continue;

            $data[$name]=$f->get();
        }

        unset($data[$model->id_field]);

        foreach ($model->_references as $our_field=>$junk) {
            if(isset($data[$our_field]) && $data[$our_field] && 
                $our_field!=$model->id_field) {

                $deref=str_replace('_id','',$our_field);
                if($deref == $our_field)continue;

                $m=$model->ref($our_field);
                if(!$m->loaded())continue;

                $data[$deref]=$m[$m->title_field];
                $data[$our_field]=new MongoID($data[$our_field]);
            }<commit_msg>make mongo more compatible with SQL<commit_after><?php
class Controller_Data_Mongo extends Controller_Data {
    function setSource($model,$table){

        if(@!$this->api->mongoclient){
            $m=new MongoClient();

            $collection=$this->api->getConfig('mongo/db');


            $this->api->mongoclient=$m->$collection;

        }

        parent::setSource($model,array(
            'db'=>$this->api->mongoclient->$table,
            'conditions'=>array(),
            'collection'=>$model->table
        ));

        //$model->data=$model->_table[$this->short_name]['db']->get($id);
    }

    /** Implemetns access to our private storage inside model */
    public function _get($model,$key){
        return $model->_table[$this->short_name][$key];
    }
    public function _set($model,$key,$val){
        $model->_table[$this->short_name][$key]=$val;
    }

    function save($model,$id=null){

        $data=array();

        foreach($model->elements as $name=>$f)if($f instanceof Field){
            if(!$f->editable() && !$f->system())continue;
            if(!isset($model->dirty[$name]) && $f->defaultValue()===null)continue;

            $data[$name]=$f->get();
        }

        unset($data[$model->id_field]);

        foreach ($model->_references as $our_field=>$junk) {
            if(isset($data[$our_field]) && $data[$our_field] && 
                $our_field!=$model->id_field) {

                $deref=str_replace('_id','',$our_field);
                if($deref == $our_field)continue;

                $m=$model->ref($our_field);
                if(!$m->loaded())continue;

                $data[$deref]=$m[$m->title_field];
                if($m instanceof Mongo_Model){
                    $data[$our_field]=new MongoID($data[$our_field]);
                }
            }
{'fraction_non_alphanumeric': 0.1938862156807246, 'fraction_numerical': 0.0, 'mean_word_length': 2.346590909090909, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369486', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1034, 'n_words': 134}