[{"data":1,"prerenderedAt":1008},["ShallowReactive",2],{"tag-model":3},[4],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"path":11,"date":12,"summary":13,"tags":14,"body":19,"_type":1001,"_id":1002,"_source":1003,"_file":1004,"_stem":1005,"_extension":1006,"sitemap":1007},"/blog/2020-12-17-magento-2-update-single-model-value","blog",false,"","Magento 2 - update single model value","Magento 2: update single model value (field) without loading the whole model instance","/blog/magento-2-update-single-model-value","2020-12-17","Often you'll get in a situation when you have to update only one model field and at the same time you don't have a model object instance. Let's take a look how to achieve this.",[15,16,17,18],"magento 2","model","sql update","development",{"type":20,"children":21,"toc":999},"root",[22,33,55,60,65,70,100,983,988,993],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27],{"type":23,"tag":28,"props":29,"children":30},"strong",{},[31],{"type":32,"value":10},"text",{"type":23,"tag":24,"props":34,"children":35},{},[36,42],{"type":23,"tag":37,"props":38,"children":41},"img",{"alt":39,"src":40},"Programing is about thinking, not writing","/images/developer.jpg",[],{"type":23,"tag":43,"props":44,"children":45},"small",{},[46],{"type":23,"tag":47,"props":48,"children":52},"a",{"href":49,"rel":50},"https://www.pexels.com/photo/person-using-a-macbook-air-4974913/?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels",[51],"nofollow",[53],{"type":32,"value":54},"Photo by olia danilevich from Pexels",{"type":23,"tag":24,"props":56,"children":57},{},[58],{"type":32,"value":59},"Well, let's say we're in above situation, and it's not applicable in our case to use the classic method where we can just use setter to set the value we want and then just persist these changes to the database.",{"type":23,"tag":24,"props":61,"children":62},{},[63],{"type":32,"value":64},"So what shall we do in such case?",{"type":23,"tag":24,"props":66,"children":67},{},[68],{"type":32,"value":69},"For me the best solution so far is to use Magento 2 App Resource instance with which you can update one or more model fields (attributes) manually - it's like you're running single SQL update statement for one table.",{"type":23,"tag":24,"props":71,"children":72},{},[73,75,82,84,90,92,98],{"type":32,"value":74},"So the easiest way and most-common - also recommended, is to inject the instance of class ",{"type":23,"tag":76,"props":77,"children":79},"code",{"className":78},[],[80],{"type":32,"value":81},"Magento\\Framework\\App\\ResourceConnection",{"type":32,"value":83}," into ",{"type":23,"tag":76,"props":85,"children":87},{"className":86},[],[88],{"type":32,"value":89},"construct",{"type":32,"value":91}," - don't use ",{"type":23,"tag":76,"props":93,"children":95},{"className":94},[],[96],{"type":32,"value":97},"ObjectManager",{"type":32,"value":99}," just to get the instance - it's not recommended by Magento standards, and then perform the action either in some function or wrote own function and call it on place you need it.",{"type":23,"tag":101,"props":102,"children":106},"pre",{"className":103,"code":104,"language":105,"meta":8,"style":8},"language-php shiki shiki-themes material-theme-palenight","use Magento\\Framework\\App\\ResourceConnection;\nuse Psr\\Log\\LoggerInterface;\n\n/** \n * @var ResourceConnection $connection \n */\nprotected $connection;\n\n/** \n * @var LoggerInterface $logger \n */\nprotected $logger;\n\n/**\n * @param ResourceConnection $connection\n * @param LoggerInterface $logger\n */\npublic function __construct(\n    ResourceConnection $connection, \n    LoggerInterface $logger\n){\n    $this->connection = $connection;\n    $this->logger = $logger;\n}\n\n/**\n * @param $itemId\n * @param $status\n */\nprotected function updateItemStatus(int $itemId, $status): void\n{\n    try {\n        $this->connection->getConnection()->update('sales_order_item', [\n            'my_custom_product_status' => $status,\n        ],\n            $this->connection->getConnection()->quoteInto('item_id = ?', $itemId)\n        );\n    } catch (Exception $exception) {\n        $this->logger->error($exception->getMessage());\n    }\n}\n","php",[107],{"type":23,"tag":76,"props":108,"children":109},{"__ignoreMap":8},[110,162,197,207,217,243,252,276,284,292,314,322,343,351,360,382,403,411,436,464,482,491,522,551,560,568,576,593,610,618,677,686,701,762,798,807,871,880,922,966,975],{"type":23,"tag":111,"props":112,"children":115},"span",{"class":113,"line":114},"line",1,[116,122,128,134,139,143,148,152,157],{"type":23,"tag":111,"props":117,"children":119},{"style":118},"--shiki-default:#F78C6C",[120],{"type":32,"value":121},"use",{"type":23,"tag":111,"props":123,"children":125},{"style":124},"--shiki-default:#BABED8",[126],{"type":32,"value":127}," Magento",{"type":23,"tag":111,"props":129,"children":131},{"style":130},"--shiki-default:#89DDFF",[132],{"type":32,"value":133},"\\",{"type":23,"tag":111,"props":135,"children":136},{"style":124},[137],{"type":32,"value":138},"Framework",{"type":23,"tag":111,"props":140,"children":141},{"style":130},[142],{"type":32,"value":133},{"type":23,"tag":111,"props":144,"children":145},{"style":124},[146],{"type":32,"value":147},"App",{"type":23,"tag":111,"props":149,"children":150},{"style":130},[151],{"type":32,"value":133},{"type":23,"tag":111,"props":153,"children":154},{"style":124},[155],{"type":32,"value":156},"ResourceConnection",{"type":23,"tag":111,"props":158,"children":159},{"style":130},[160],{"type":32,"value":161},";\n",{"type":23,"tag":111,"props":163,"children":165},{"class":113,"line":164},2,[166,170,175,179,184,188,193],{"type":23,"tag":111,"props":167,"children":168},{"style":118},[169],{"type":32,"value":121},{"type":23,"tag":111,"props":171,"children":172},{"style":124},[173],{"type":32,"value":174}," Psr",{"type":23,"tag":111,"props":176,"children":177},{"style":130},[178],{"type":32,"value":133},{"type":23,"tag":111,"props":180,"children":181},{"style":124},[182],{"type":32,"value":183},"Log",{"type":23,"tag":111,"props":185,"children":186},{"style":130},[187],{"type":32,"value":133},{"type":23,"tag":111,"props":189,"children":190},{"style":124},[191],{"type":32,"value":192},"LoggerInterface",{"type":23,"tag":111,"props":194,"children":195},{"style":130},[196],{"type":32,"value":161},{"type":23,"tag":111,"props":198,"children":200},{"class":113,"line":199},3,[201],{"type":23,"tag":111,"props":202,"children":204},{"emptyLinePlaceholder":203},true,[205],{"type":32,"value":206},"\n",{"type":23,"tag":111,"props":208,"children":210},{"class":113,"line":209},4,[211],{"type":23,"tag":111,"props":212,"children":214},{"style":213},"--shiki-default:#676E95;--shiki-default-font-style:italic",[215],{"type":32,"value":216},"/** \n",{"type":23,"tag":111,"props":218,"children":220},{"class":113,"line":219},5,[221,226,232,238],{"type":23,"tag":111,"props":222,"children":223},{"style":213},[224],{"type":32,"value":225}," * ",{"type":23,"tag":111,"props":227,"children":229},{"style":228},"--shiki-default:#F78C6C;--shiki-default-font-style:italic",[230],{"type":32,"value":231},"@var",{"type":23,"tag":111,"props":233,"children":235},{"style":234},"--shiki-default:#FFCB6B;--shiki-default-font-style:italic",[236],{"type":32,"value":237}," ResourceConnection",{"type":23,"tag":111,"props":239,"children":240},{"style":213},[241],{"type":32,"value":242}," $connection \n",{"type":23,"tag":111,"props":244,"children":246},{"class":113,"line":245},6,[247],{"type":23,"tag":111,"props":248,"children":249},{"style":213},[250],{"type":32,"value":251}," */\n",{"type":23,"tag":111,"props":253,"children":255},{"class":113,"line":254},7,[256,262,267,272],{"type":23,"tag":111,"props":257,"children":259},{"style":258},"--shiki-default:#C792EA",[260],{"type":32,"value":261},"protected",{"type":23,"tag":111,"props":263,"children":264},{"style":130},[265],{"type":32,"value":266}," $",{"type":23,"tag":111,"props":268,"children":269},{"style":124},[270],{"type":32,"value":271},"connection",{"type":23,"tag":111,"props":273,"children":274},{"style":130},[275],{"type":32,"value":161},{"type":23,"tag":111,"props":277,"children":279},{"class":113,"line":278},8,[280],{"type":23,"tag":111,"props":281,"children":282},{"emptyLinePlaceholder":203},[283],{"type":32,"value":206},{"type":23,"tag":111,"props":285,"children":287},{"class":113,"line":286},9,[288],{"type":23,"tag":111,"props":289,"children":290},{"style":213},[291],{"type":32,"value":216},{"type":23,"tag":111,"props":293,"children":295},{"class":113,"line":294},10,[296,300,304,309],{"type":23,"tag":111,"props":297,"children":298},{"style":213},[299],{"type":32,"value":225},{"type":23,"tag":111,"props":301,"children":302},{"style":228},[303],{"type":32,"value":231},{"type":23,"tag":111,"props":305,"children":306},{"style":234},[307],{"type":32,"value":308}," LoggerInterface",{"type":23,"tag":111,"props":310,"children":311},{"style":213},[312],{"type":32,"value":313}," $logger \n",{"type":23,"tag":111,"props":315,"children":317},{"class":113,"line":316},11,[318],{"type":23,"tag":111,"props":319,"children":320},{"style":213},[321],{"type":32,"value":251},{"type":23,"tag":111,"props":323,"children":325},{"class":113,"line":324},12,[326,330,334,339],{"type":23,"tag":111,"props":327,"children":328},{"style":258},[329],{"type":32,"value":261},{"type":23,"tag":111,"props":331,"children":332},{"style":130},[333],{"type":32,"value":266},{"type":23,"tag":111,"props":335,"children":336},{"style":124},[337],{"type":32,"value":338},"logger",{"type":23,"tag":111,"props":340,"children":341},{"style":130},[342],{"type":32,"value":161},{"type":23,"tag":111,"props":344,"children":346},{"class":113,"line":345},13,[347],{"type":23,"tag":111,"props":348,"children":349},{"emptyLinePlaceholder":203},[350],{"type":32,"value":206},{"type":23,"tag":111,"props":352,"children":354},{"class":113,"line":353},14,[355],{"type":23,"tag":111,"props":356,"children":357},{"style":213},[358],{"type":32,"value":359},"/**\n",{"type":23,"tag":111,"props":361,"children":363},{"class":113,"line":362},15,[364,368,373,377],{"type":23,"tag":111,"props":365,"children":366},{"style":213},[367],{"type":32,"value":225},{"type":23,"tag":111,"props":369,"children":370},{"style":228},[371],{"type":32,"value":372},"@param",{"type":23,"tag":111,"props":374,"children":375},{"style":234},[376],{"type":32,"value":237},{"type":23,"tag":111,"props":378,"children":379},{"style":213},[380],{"type":32,"value":381}," $connection\n",{"type":23,"tag":111,"props":383,"children":385},{"class":113,"line":384},16,[386,390,394,398],{"type":23,"tag":111,"props":387,"children":388},{"style":213},[389],{"type":32,"value":225},{"type":23,"tag":111,"props":391,"children":392},{"style":228},[393],{"type":32,"value":372},{"type":23,"tag":111,"props":395,"children":396},{"style":234},[397],{"type":32,"value":308},{"type":23,"tag":111,"props":399,"children":400},{"style":213},[401],{"type":32,"value":402}," $logger\n",{"type":23,"tag":111,"props":404,"children":406},{"class":113,"line":405},17,[407],{"type":23,"tag":111,"props":408,"children":409},{"style":213},[410],{"type":32,"value":251},{"type":23,"tag":111,"props":412,"children":414},{"class":113,"line":413},18,[415,420,425,431],{"type":23,"tag":111,"props":416,"children":417},{"style":258},[418],{"type":32,"value":419},"public",{"type":23,"tag":111,"props":421,"children":422},{"style":258},[423],{"type":32,"value":424}," function",{"type":23,"tag":111,"props":426,"children":428},{"style":427},"--shiki-default:#82AAFF",[429],{"type":32,"value":430}," __construct",{"type":23,"tag":111,"props":432,"children":433},{"style":130},[434],{"type":32,"value":435},"(\n",{"type":23,"tag":111,"props":437,"children":439},{"class":113,"line":438},19,[440,446,450,454,459],{"type":23,"tag":111,"props":441,"children":443},{"style":442},"--shiki-default:#FFCB6B",[444],{"type":32,"value":445},"    ResourceConnection",{"type":23,"tag":111,"props":447,"children":448},{"style":130},[449],{"type":32,"value":266},{"type":23,"tag":111,"props":451,"children":452},{"style":124},[453],{"type":32,"value":271},{"type":23,"tag":111,"props":455,"children":456},{"style":130},[457],{"type":32,"value":458},",",{"type":23,"tag":111,"props":460,"children":461},{"style":124},[462],{"type":32,"value":463}," \n",{"type":23,"tag":111,"props":465,"children":467},{"class":113,"line":466},20,[468,473,477],{"type":23,"tag":111,"props":469,"children":470},{"style":442},[471],{"type":32,"value":472},"    LoggerInterface",{"type":23,"tag":111,"props":474,"children":475},{"style":130},[476],{"type":32,"value":266},{"type":23,"tag":111,"props":478,"children":479},{"style":124},[480],{"type":32,"value":481},"logger\n",{"type":23,"tag":111,"props":483,"children":485},{"class":113,"line":484},21,[486],{"type":23,"tag":111,"props":487,"children":488},{"style":130},[489],{"type":32,"value":490},"){\n",{"type":23,"tag":111,"props":492,"children":494},{"class":113,"line":493},22,[495,500,505,510,514,518],{"type":23,"tag":111,"props":496,"children":497},{"style":130},[498],{"type":32,"value":499},"    $this->",{"type":23,"tag":111,"props":501,"children":502},{"style":124},[503],{"type":32,"value":504},"connection ",{"type":23,"tag":111,"props":506,"children":507},{"style":130},[508],{"type":32,"value":509},"=",{"type":23,"tag":111,"props":511,"children":512},{"style":130},[513],{"type":32,"value":266},{"type":23,"tag":111,"props":515,"children":516},{"style":124},[517],{"type":32,"value":271},{"type":23,"tag":111,"props":519,"children":520},{"style":130},[521],{"type":32,"value":161},{"type":23,"tag":111,"props":523,"children":525},{"class":113,"line":524},23,[526,530,535,539,543,547],{"type":23,"tag":111,"props":527,"children":528},{"style":130},[529],{"type":32,"value":499},{"type":23,"tag":111,"props":531,"children":532},{"style":124},[533],{"type":32,"value":534},"logger ",{"type":23,"tag":111,"props":536,"children":537},{"style":130},[538],{"type":32,"value":509},{"type":23,"tag":111,"props":540,"children":541},{"style":130},[542],{"type":32,"value":266},{"type":23,"tag":111,"props":544,"children":545},{"style":124},[546],{"type":32,"value":338},{"type":23,"tag":111,"props":548,"children":549},{"style":130},[550],{"type":32,"value":161},{"type":23,"tag":111,"props":552,"children":554},{"class":113,"line":553},24,[555],{"type":23,"tag":111,"props":556,"children":557},{"style":130},[558],{"type":32,"value":559},"}\n",{"type":23,"tag":111,"props":561,"children":563},{"class":113,"line":562},25,[564],{"type":23,"tag":111,"props":565,"children":566},{"emptyLinePlaceholder":203},[567],{"type":32,"value":206},{"type":23,"tag":111,"props":569,"children":571},{"class":113,"line":570},26,[572],{"type":23,"tag":111,"props":573,"children":574},{"style":213},[575],{"type":32,"value":359},{"type":23,"tag":111,"props":577,"children":579},{"class":113,"line":578},27,[580,584,588],{"type":23,"tag":111,"props":581,"children":582},{"style":213},[583],{"type":32,"value":225},{"type":23,"tag":111,"props":585,"children":586},{"style":228},[587],{"type":32,"value":372},{"type":23,"tag":111,"props":589,"children":590},{"style":213},[591],{"type":32,"value":592}," $itemId\n",{"type":23,"tag":111,"props":594,"children":596},{"class":113,"line":595},28,[597,601,605],{"type":23,"tag":111,"props":598,"children":599},{"style":213},[600],{"type":32,"value":225},{"type":23,"tag":111,"props":602,"children":603},{"style":228},[604],{"type":32,"value":372},{"type":23,"tag":111,"props":606,"children":607},{"style":213},[608],{"type":32,"value":609}," $status\n",{"type":23,"tag":111,"props":611,"children":613},{"class":113,"line":612},29,[614],{"type":23,"tag":111,"props":615,"children":616},{"style":213},[617],{"type":32,"value":251},{"type":23,"tag":111,"props":619,"children":621},{"class":113,"line":620},30,[622,626,630,635,640,645,649,654,658,662,667,672],{"type":23,"tag":111,"props":623,"children":624},{"style":258},[625],{"type":32,"value":261},{"type":23,"tag":111,"props":627,"children":628},{"style":258},[629],{"type":32,"value":424},{"type":23,"tag":111,"props":631,"children":632},{"style":427},[633],{"type":32,"value":634}," updateItemStatus",{"type":23,"tag":111,"props":636,"children":637},{"style":130},[638],{"type":32,"value":639},"(",{"type":23,"tag":111,"props":641,"children":642},{"style":118},[643],{"type":32,"value":644},"int",{"type":23,"tag":111,"props":646,"children":647},{"style":130},[648],{"type":32,"value":266},{"type":23,"tag":111,"props":650,"children":651},{"style":124},[652],{"type":32,"value":653},"itemId",{"type":23,"tag":111,"props":655,"children":656},{"style":130},[657],{"type":32,"value":458},{"type":23,"tag":111,"props":659,"children":660},{"style":130},[661],{"type":32,"value":266},{"type":23,"tag":111,"props":663,"children":664},{"style":124},[665],{"type":32,"value":666},"status",{"type":23,"tag":111,"props":668,"children":669},{"style":130},[670],{"type":32,"value":671},"):",{"type":23,"tag":111,"props":673,"children":674},{"style":118},[675],{"type":32,"value":676}," void\n",{"type":23,"tag":111,"props":678,"children":680},{"class":113,"line":679},31,[681],{"type":23,"tag":111,"props":682,"children":683},{"style":130},[684],{"type":32,"value":685},"{\n",{"type":23,"tag":111,"props":687,"children":689},{"class":113,"line":688},32,[690,696],{"type":23,"tag":111,"props":691,"children":693},{"style":692},"--shiki-default:#89DDFF;--shiki-default-font-style:italic",[694],{"type":32,"value":695},"    try",{"type":23,"tag":111,"props":697,"children":698},{"style":130},[699],{"type":32,"value":700}," {\n",{"type":23,"tag":111,"props":702,"children":704},{"class":113,"line":703},33,[705,710,714,719,724,729,734,738,743,749,753,757],{"type":23,"tag":111,"props":706,"children":707},{"style":130},[708],{"type":32,"value":709},"        $this->",{"type":23,"tag":111,"props":711,"children":712},{"style":124},[713],{"type":32,"value":271},{"type":23,"tag":111,"props":715,"children":716},{"style":130},[717],{"type":32,"value":718},"->",{"type":23,"tag":111,"props":720,"children":721},{"style":427},[722],{"type":32,"value":723},"getConnection",{"type":23,"tag":111,"props":725,"children":726},{"style":130},[727],{"type":32,"value":728},"()->",{"type":23,"tag":111,"props":730,"children":731},{"style":427},[732],{"type":32,"value":733},"update",{"type":23,"tag":111,"props":735,"children":736},{"style":130},[737],{"type":32,"value":639},{"type":23,"tag":111,"props":739,"children":740},{"style":130},[741],{"type":32,"value":742},"'",{"type":23,"tag":111,"props":744,"children":746},{"style":745},"--shiki-default:#C3E88D",[747],{"type":32,"value":748},"sales_order_item",{"type":23,"tag":111,"props":750,"children":751},{"style":130},[752],{"type":32,"value":742},{"type":23,"tag":111,"props":754,"children":755},{"style":130},[756],{"type":32,"value":458},{"type":23,"tag":111,"props":758,"children":759},{"style":130},[760],{"type":32,"value":761}," [\n",{"type":23,"tag":111,"props":763,"children":765},{"class":113,"line":764},34,[766,771,776,780,785,789,793],{"type":23,"tag":111,"props":767,"children":768},{"style":130},[769],{"type":32,"value":770},"            '",{"type":23,"tag":111,"props":772,"children":773},{"style":745},[774],{"type":32,"value":775},"my_custom_product_status",{"type":23,"tag":111,"props":777,"children":778},{"style":130},[779],{"type":32,"value":742},{"type":23,"tag":111,"props":781,"children":782},{"style":130},[783],{"type":32,"value":784}," =>",{"type":23,"tag":111,"props":786,"children":787},{"style":130},[788],{"type":32,"value":266},{"type":23,"tag":111,"props":790,"children":791},{"style":124},[792],{"type":32,"value":666},{"type":23,"tag":111,"props":794,"children":795},{"style":130},[796],{"type":32,"value":797},",\n",{"type":23,"tag":111,"props":799,"children":801},{"class":113,"line":800},35,[802],{"type":23,"tag":111,"props":803,"children":804},{"style":130},[805],{"type":32,"value":806},"        ],\n",{"type":23,"tag":111,"props":808,"children":810},{"class":113,"line":809},36,[811,816,820,824,828,832,837,841,845,850,854,858,862,866],{"type":23,"tag":111,"props":812,"children":813},{"style":130},[814],{"type":32,"value":815},"            $this->",{"type":23,"tag":111,"props":817,"children":818},{"style":124},[819],{"type":32,"value":271},{"type":23,"tag":111,"props":821,"children":822},{"style":130},[823],{"type":32,"value":718},{"type":23,"tag":111,"props":825,"children":826},{"style":427},[827],{"type":32,"value":723},{"type":23,"tag":111,"props":829,"children":830},{"style":130},[831],{"type":32,"value":728},{"type":23,"tag":111,"props":833,"children":834},{"style":427},[835],{"type":32,"value":836},"quoteInto",{"type":23,"tag":111,"props":838,"children":839},{"style":130},[840],{"type":32,"value":639},{"type":23,"tag":111,"props":842,"children":843},{"style":130},[844],{"type":32,"value":742},{"type":23,"tag":111,"props":846,"children":847},{"style":745},[848],{"type":32,"value":849},"item_id = ?",{"type":23,"tag":111,"props":851,"children":852},{"style":130},[853],{"type":32,"value":742},{"type":23,"tag":111,"props":855,"children":856},{"style":130},[857],{"type":32,"value":458},{"type":23,"tag":111,"props":859,"children":860},{"style":130},[861],{"type":32,"value":266},{"type":23,"tag":111,"props":863,"children":864},{"style":124},[865],{"type":32,"value":653},{"type":23,"tag":111,"props":867,"children":868},{"style":130},[869],{"type":32,"value":870},")\n",{"type":23,"tag":111,"props":872,"children":874},{"class":113,"line":873},37,[875],{"type":23,"tag":111,"props":876,"children":877},{"style":130},[878],{"type":32,"value":879},"        );\n",{"type":23,"tag":111,"props":881,"children":883},{"class":113,"line":882},38,[884,889,894,899,904,908,913,918],{"type":23,"tag":111,"props":885,"children":886},{"style":130},[887],{"type":32,"value":888},"    }",{"type":23,"tag":111,"props":890,"children":891},{"style":692},[892],{"type":32,"value":893}," catch",{"type":23,"tag":111,"props":895,"children":896},{"style":130},[897],{"type":32,"value":898}," (",{"type":23,"tag":111,"props":900,"children":901},{"style":442},[902],{"type":32,"value":903},"Exception",{"type":23,"tag":111,"props":905,"children":906},{"style":130},[907],{"type":32,"value":266},{"type":23,"tag":111,"props":909,"children":910},{"style":124},[911],{"type":32,"value":912},"exception",{"type":23,"tag":111,"props":914,"children":915},{"style":130},[916],{"type":32,"value":917},")",{"type":23,"tag":111,"props":919,"children":920},{"style":130},[921],{"type":32,"value":700},{"type":23,"tag":111,"props":923,"children":925},{"class":113,"line":924},39,[926,930,934,938,943,948,952,956,961],{"type":23,"tag":111,"props":927,"children":928},{"style":130},[929],{"type":32,"value":709},{"type":23,"tag":111,"props":931,"children":932},{"style":124},[933],{"type":32,"value":338},{"type":23,"tag":111,"props":935,"children":936},{"style":130},[937],{"type":32,"value":718},{"type":23,"tag":111,"props":939,"children":940},{"style":427},[941],{"type":32,"value":942},"error",{"type":23,"tag":111,"props":944,"children":945},{"style":130},[946],{"type":32,"value":947},"($",{"type":23,"tag":111,"props":949,"children":950},{"style":124},[951],{"type":32,"value":912},{"type":23,"tag":111,"props":953,"children":954},{"style":130},[955],{"type":32,"value":718},{"type":23,"tag":111,"props":957,"children":958},{"style":427},[959],{"type":32,"value":960},"getMessage",{"type":23,"tag":111,"props":962,"children":963},{"style":130},[964],{"type":32,"value":965},"());\n",{"type":23,"tag":111,"props":967,"children":969},{"class":113,"line":968},40,[970],{"type":23,"tag":111,"props":971,"children":972},{"style":130},[973],{"type":32,"value":974},"    }\n",{"type":23,"tag":111,"props":976,"children":978},{"class":113,"line":977},41,[979],{"type":23,"tag":111,"props":980,"children":981},{"style":130},[982],{"type":32,"value":559},{"type":23,"tag":24,"props":984,"children":985},{},[986],{"type":32,"value":987},"This way we can easily update, in our case model Sales_order_item, attribute on some model without the need to use repository or factory to load the whole model with all attributes when we have to update only one single attribute.",{"type":23,"tag":24,"props":989,"children":990},{},[991],{"type":32,"value":992},"I hope this will help you and you'll find it useful!",{"type":23,"tag":994,"props":995,"children":996},"style",{},[997],{"type":32,"value":998},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":8,"searchDepth":164,"depth":164,"links":1000},[],"markdown","content:blog:2020-12-17-magento-2-update-single-model-value.md","content","blog/2020-12-17-magento-2-update-single-model-value.md","blog/2020-12-17-magento-2-update-single-model-value","md",{"loc":11},1769006887457]