質問 > 管理機能 > entityのリレーションの仕方が分からない |
管理機能
スレッド表示 | 古いものから | 前のトピック | 次のトピック | 下へ |
投稿者 | スレッド |
---|---|
xaiam |
投稿日時: 2020/6/10 21:53
対応状況: −−−
|
新米 登録日: 2020/6/10 居住地: 投稿: 10 |
Re: entityのリレーションの仕方が分からない 助かりました!
|
ゲスト |
投稿日時: 2020/6/10 20:00
対応状況: −−−
|
Re: entityのリレーションの仕方が分からない CustomerTraitはEntityではないので、CustomerRankのcustomersにつけているアノテーションを以下のようにすると動作すると思います。
|
|
xaiam |
投稿日時: 2020/6/10 18:57
対応状況: −−−
|
新米 登録日: 2020/6/10 居住地: 投稿: 10 |
entityのリレーションの仕方が分からない ▼テンプレート
[EC-CUBE] ec-cube4.0.4 [レンタルサーバ] localhost [OS] macos catalina 10.15.14 [PHP] PHP 7.2.30 (cli) [データベース] mysql Ver 14.14 Distrib 5.7.28, for osx10.15 (x86_64) using EditLine wrapper [WEBサーバ] Symfony Local Server v4.16.1 [ブラウザ] Chrome最新 [導入プラグインの有無] [カスタマイズの有無] [現象] ec-cube/app/Customize/Entity直下にsrc/下にあるentityであるCustomer.phpをカスタムする用のCustomerTrait.phpを作成しbin/console e:g:pをやったあとさらに上記フォルダ内にCustomerRank.phpとCustomerChannel.phpという二つの新規テーブルを作成するためのentityを作成しbin/console d:s:update --dump-sqlをやったら `The target-entity Eccube\Entity\CustomerRank cannot be found in 'Eccube\Entity\Customer#customerRanks'.` と出ます。 対策はありますか?リレーションのやり方がわかっていませんのでそのやり方が書いてあるページやサイトを貼っていただくかここで教えていただければと思います。 ```php:CustomerTrait.php <?php namespace Customize\Entity; use Doctrine\ORM\Mapping as ORM; use Eccube\Annotation\EntityExtension; /** * @EntityExtension("Eccube\Entity\Customer") */ trait CustomerTrait { /** * @ORM\Column(type="string", nullable=true) */ private $maker_name; /** * @ORM\ManyToOne(targetEntity="CustomerRank", inversedBy="customers") */ private $customerRanks; public function getMaker_name(): ?string { return $this->maker_name; } public function setMaker_name(?string $maker_name): self { $this->maker_name = $maker_name; return $this; } } ``` ---------------------------- ```php:CustomerRank.php <?php namespace Customize\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass="Customize\Repository\CustomerRankRepository") */ class CustomerRank { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\OneToMany(targetEntity="CustomerTrait", mappedBy="customerRanks") */ private $customers; /** * @ORM\ManyToOne(targetEntity="CustomerChannel", inversedBy="customerRanks") */ private $customerChannels; /** * Constructor */ public function __construct() { $this->customers = new \Doctrine\Common\Collections\ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } } ``` ------------------------ ```php:CustomerChannel.php <?php namespace Customize\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass="Customize\Repository\CustomerChannelRepository") */ class CustomerChannel { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\OneToMany(targetEntity="CustomerRank", mappedBy="customerChannels") */ private $customerRanks; public function __construct() { $this->customerRanks = new \Doctrine\Common\Collections\ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } } ``` |
スレッド表示 | 古いものから | 前のトピック | 次のトピック | トップ |