Laravel - 2 queries over nothing? -
hello guys,
in official doc of eloquent laravel, way make update table :
$flight = app\flight::find(1); $flight->name = 'new flight name'; $flight->save();
i must say, don't understand that. me, means basic update, there 2 queries database - select , update ?
anyone explain me why solution ?
thanks !
any abstraction used complex applications. code simple can not feel advantage. object relation mapping (orm) used hide details of operating databases, or running sql queries.
just mvc model, different layers in charge of different fields.
view: render html
controller: logical control, if .. else ..
model: data access, data modification , persistence.
the controller layer won't take care of how model layer works, find object $flight
, , change property, , save()
. natural , neat. controller layer object modifying, instead of data modifying.
by separating data , object, can easily, or @ lease possibly, change implementation of data persistence.
if objects changed, can save on redis
or memcached
or other nosql
storage. controller layer's code needs no change.
if objects large , not modify quite often, can consider using distributed storage, or using lazy loading
techniques. controller code unchanged. change model layer's implementation, upper codes not aware of change.
decoupling or layering codes, makes easy change layer's implementation. if think wring 2 lines of sql queries quicker orm, maybe need experience larger projects highly demand changing , performance optimization.
it separating implementation , usage.
edit:
you can use where
, update
update id. see http://laravel.com/docs/5.1/eloquent#basic-updates
app\flight::where('active', 1) ->where('destination', 'san diego') ->update(['delayed' => 1]);
Comments
Post a Comment