Is there a way to update a record in a table using an ORM model without any extra queries?
I know that I can simply use DB object to do a raw query, but I would like to do it with an ORM object.
I have the following code.
$orm = ORM::factory("myobject",1);
$orm->name = "new name";
$orm->save();
the problem of the code is that it executes a select query then executes an update query.
I've tried the following as well.
ORM::factory("myobject")->values(array("id"=>1, "name"=>"my new name"))-save();
the problem of this query is that the ORM executes "show full columns from myobject"
How do I make an update query on an ORM object without executing any extra queries?
The reason you get the
show full columns for ..
query is that you don't have defined$_table_columns
, where the table column data for that object is stored. Kohana needs to know these so you can set values to that object.E.g.
And to answer your question. The second way seems like the right way to do it :) As soon as you've done the above the 'extra' query should be gone