LoginSignup
0
0

More than 5 years have passed since last update.

OneToOne データ更新(Update)

Posted at

はじめに

OneToOneの関係のテーブルにデータを更新(Update)する。
OneToOne データ取得(Select)」の続き。

データ更新(Update)

Controllerよりアクセス

ControllerからRepository経由でアクセス

app/Customize/Controller/SamplePageController.php
/**
 * @Route("/sample/{id}", name="sample_index")
 * @Template("Sample/index.twig")
 */
public function index($id)
{
    $product = $this->productRepository->find($id);
    dump($product);

    $size_a = $product->getProductSize()->getSizeA();
    $product->getProductSize()->setSizeA($size_a + 1);
    $this->entityManager->persist($product);
    $this->entityManager->flush();

    return [
        'shop_name' => $this->baseInfo->getShopName(),
        'product_name' => $product->getName(),
        'maker_name' => $product->getMakerName(),
        'size_a' => $product->getProductSize()->getSizeA(),
    ];
}

ブラウザよりアクセス

/sample/1 でdtb_product_sizeのデータを更新できた。

まとめ

find()して値を設定してpersist()してflush()

参照

OneToOne データ取得(Select)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0