質問 > その他 > 双方向リレーションいついて |
その他
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | 下へ |
投稿者 | スレッド |
---|---|
kenshi |
投稿日時: 2020/12/1 16:08
対応状況: 確認中
|
一人前 登録日: 2020/6/29 居住地: 投稿: 83 |
双方向リレーションいついて わかりやすかったので
こちらのサイトを参考に実装しています。 https://qiita.com/ma33588/items/352abb3e73e2f1140e61 片方の「customer_id」保持テーブルは、上手く取得できる。 Customerの方から取得ができない @ORM\OneToMany mappedBy="Customer" デバックの一部 -DistributeCodes: PersistentCollection {#15841 ▼ -snapshot: [] -owner: Customer {#15941} -association: array:15 [ …15] -em: EntityManager {#6682 …11} -backRefFieldName: "Customer" -typeClass: ClassMetadata {#15848 …} -isDirty: false #collection: ArrayCollection {#15843 ▶} #initialized: false 上手く取得できていない、、、 ご教授お願いいたします。 |
kenshi |
投稿日時: 2020/12/2 8:55
対応状況: −−−
|
一人前 登録日: 2020/6/29 居住地: 投稿: 83 |
Re: 双方向リレーションいついて 追加情報
こちらのメソッドで上手く行かないです。 CustomerTrait /** * @return Collection|CheckCode[] */ public function getCheckCodes(): Collection { return $this->CheckCodes; } エラー内容 Type error: Return value of Eccube\Entity\Customer::getCheckCodes() must be an instance of Customize\Entity\Collection, instance of Doctrine\ORM\PersistentCollection returned |
kenshi |
投稿日時: 2020/12/2 10:24
対応状況: −−−
|
一人前 登録日: 2020/6/29 居住地: 投稿: 83 |
Re: 双方向リレーションいついて そのまま取得できないので、ripositoryでjoinして取得しました。
データ構成変更したいのですが可能でしょうか? 一つしか紐づかないので「0」を指定したくないのですが、 方法がわかれば教えてください。 Customer.CheckCodes[0] ↓ Customer.CheckCodes PersistentCollection {#2959 ▼ -snapshot: array:1 [ …1] -owner: Customer {#2821 ▶} -association: array:15 [ …15] -em: EntityManager {#203 …11} -backRefFieldName: "Customer" -typeClass: ClassMetadata {#2759 …} -isDirty: false #collection: ArrayCollection {#2960 ▼ -elements: array:1 [▼ 0 => CheckCode {#2957 ▼ -id: 1 -code: "1234567890" -set_date: DateTime @1605052800 {#2804 ▶} -end_date: DateTime @1609372800 {#2810 ▶} -create_date: DateTime @1605052800 {#2811 ▶} -update_date: DateTime @1605052800 {#2822 ▶} -Customer: Customer {#2821 ▶} -AnnotationReader: AnnotationReader {#381 ▶} } ] } #initialized: true } |
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | トップ |