kohanakohana-3kohana-orm

Kohana 3 ORM - How to tell if the current model being saved is new?


In my ORM model, I'd like to save some default values which are calculated based on other values. The best I could come up with is:

function save(){
    if( ! $this->loaded()){
        // Set values here
    }
    parent::save();
}

Does anybody know if there is a better/recommended way to do this, or should this be sufficient for most cases? Thanks :)


Solution

  • Your implementation is good. The only improvement you could do is just replace your condition to:

    if (!$this->_loaded) {