バージョン選択

フォーラム

メニュー

オンライン状況

54 人のユーザが現在オンラインです。 (45 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 54
もっと...

サイト内検索

質問 > 管理機能 > entityのリレーションの仕方が分からない

管理機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
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;
}
}

```
ゲスト
投稿日時: 2020/6/10 20:00
対応状況: −−−
Re: entityのリレーションの仕方が分からない
CustomerTraitはEntityではないので、CustomerRankのcustomersにつけているアノテーションを以下のようにすると動作すると思います。

@ORM\OneToMany(targetEntity="Eccube\Entity\Customer", mappedBy="customerRanks")
xaiam
投稿日時: 2020/6/10 21:53
対応状況: −−−
新米
登録日: 2020/6/10
居住地:
投稿: 10
Re: entityのリレーションの仕方が分からない
助かりました!
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,711名です
総投稿数は109,948件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2313
5
umebius
2085
6
yuh
1819
7
h_tanaka
1638
8
red
1570
9
mcontact
1285
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.