Symfony和学说如何获取协会和相关实体 [英] How Symfony and Doctrine fetches associations and related entities

查看:226
本文介绍了Symfony和学说如何获取协会和相关实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的头撞在努力实现Symfony和学说如何获取相关实体。

I cracked my head trying to realize how Symfony and Doctrine fetch associated entities.

让我们想象一下:我有几个相关的实体:

Lets imagine: i have several associated entities:


  • 公司(多对一到城)

  • 城(多对一到区域,到一对多公司)

  • 地区(多对一到乡村,到一对多城)

  • 国家(一对多到区域)

在我公司呈现形式我创建表单事件侦听器(上pre_SET_DATA)中插入地区和国家selectboxes这种形式。
这些字段中的值必须根据相关联的国家或地区来设置。

When i render Company form i create Form Event Listener (on PRE_SET_DATA) that inserts Region and Country selectboxes to this form. The values in these fields must be set according to associated Region.

我通过检索当前公司所在地区:

I retrieve current Company Region via:

$company = $event->getData();
$city = $company->getCity()

这工作好

但是当我尝试这样的:

$region = $city->getRegion(); // returns NULL
$country = $region->getCountry(); // returns NULL

这些方法返回NULL。但实际上所有关联的存在与条令关联映射是正确的。 为什么?

据学说文档:当我呼吁代理对象吸气剂(这些ovjects是代理,对吧?) - 学说应该从数据库中获取足够的数据和更新对象。
事实上 - 方法返回空值

According to Doctrine documentation: when i call getter for the proxy object (these ovjects are proxies, right?) - Doctrine should fetch insufficient data from database and update the object. In fact - methods return NULLs.

我怎样才能得到任何相关的实体? (从任何关联的深层次)

推荐答案

我只需要删除缓存目录...

I just needed to remove cache dir...

这篇关于Symfony和学说如何获取协会和相关实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆