TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
copy method in ORM module
  • It's as simple as this :

    public function copy() {
        return clone $this;

    Let's say you have to apply a count_all() method before limiting and filtering your model, you can apply this to a copy like the following :

    $foo = ORM::factory("foo");
    $count = foo
        ->where("foo", ">", "foo")
    $results = $foo->find_all();

    It's by far a much cleaner way to work instead of handling multiple instances. However, if the clone is saved, it will get confilcted with its original.

  • Why not:

    $foo = ORM::factory('Foo') ->where('foo', '=', 'bar');

    $count = $foo->reset(FALSE) ->count_all();

    $foos = $foo->find_all();

  • Using reset(FALSE) can have problems if the query was built including ORM::with().

  • Reset cleans the query, which is not always desired. I just need to fetch two time, but not have to rebuild twice the same conditions. I think it's relevent enough to end in the default api.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion