ormkohanakohana-3kohana-orm

Want to use Query builder in Kohana3 ORM


I want to use Query builder methods in Kohana 3 ORM so is it possbile to do that? And I want some of my function inside Kohana ORM based Model, for example if I do some thing in a function and it belongs to some model that is already an ORM based Model then I want to write that function in it and is it possible that I can use Query Builder or ORM inside those methods or class? like

class Abc_Model extends ORM{
    function setAbc($a){
          DB::insert($table,$a);
    }

    function getSomething(){
         $x=$this->x->find_all();
         return $x;
    }


 }

So can I do such things in ORM and how and will it be a good approach?


Solution

  • You can use query builder methods on ORM objects anywhere, thanks to __call().

    So:

    // inside the model
    public function find_all_specific($val)
    {
        return $this->where('specific','=',$val)->find_all();
    }
    

    There are quite a few good docs on using Ko3 ORM, you can start with userguide:

    http://kohanaframework.org/3.1/guide/orm/using (switch to 3.0 if you're using 3.0.x)