Symfony2 YAML实体字段未绑定 [英] Symfony2 YAML Entity field not being bound

查看:72
本文介绍了Symfony2 YAML实体字段未绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Symfony2的项目。我应该说,我不认为自己是Symfony2的主人。你可以说我是一个新手。



我的实体通过YAML绑定到数据库,一个Entity类是在没有注释的PHP中创建的。



我有一个实体喜欢这样:

 项目/ CoreBundle / Resources / config / doctrine /Card.orm.yml 

项目/ CoreBundle / Entity / Card.php

卡 - 是一个仪表板元素,可以拖动以方便用户。



相应的Card.orm.yml和Card.php具有对应于表格的结构在db。我创建了这段代码,工作正常。



问题:现在我尝试向表,orm和Entity添加更多的字段,它们没有被Symfony2 / Doctrine2查询(我在调试器中查找,甚至在查询新的字段中都是SELECT)。



更多的是,我尝试添加任何字段它不会变得束缚。在检索对象中,它始终为NULL。我查找了该实体的MAPPING,该字段是BEING MAPPED。但是在select查询中,它再也不存在。我已经使用了清晰的缓存机制,而且没有工作。我从orm和实体中删除了其他字段 - Doctrine2抛出异常,但是当我删除此字段(它仍然在表中)并且工作相同时,只返回null。



这是有用的:

  $ queryBuilder 
- > select(array('card' card.isSpecialCard'))

isSpecialCard字段是未绑定的字段,所以我必须自定义选择它从表,然后它通过选择加载。此外,它正在加载到另一个级别的阵列中,即使对象仍然存在于该对象中,并且它已经被选定为有价值。



我正在使用Symfony 2.1。

解决方案

你不应该手动进行更改,而是让ORM驱动程序为你。使用这两个命令相应地更新Entity和您的数据库:

  php应用程序/控制台原则:generate:entities命名空间:卡
php app / console doctrine:schema:update --force


I have a project on Symfony2. I should say that I don't consider myself a master of Symfony2 in any way. You could say I'm a newbie.

My entities are bound via YAML to database and an Entity class is created in php not bound by annotations.

I have an Entity likes this:

Project/CoreBundle/Resources/config/doctrine/Card.orm.yml

Project/CoreBundle/Entity/Card.php

Card - is a dashboard element, that can be dragged around for user's convenience.

The corresponding Card.orm.yml and Card.php have structure that correspond to table in db. I created this piece of code and worked fine.

The Problem: now that I try to add more fields to table, to orm and Entity, they are not being selected by Symfony2/Doctrine2 query (I've looked it up in debugger and not even in query the new field is SELECTed).

More so, I try to add any field and it doesn't become bound. In retrieved object it is always NULL. I've looked up MAPPING of this entity and this field is BEING MAPPED. But in select query, again, it is not present. I've used clear caching mechanisms and such - didn’t work. I've deleted OTHER fields from orm and entity - Doctrine2 throws exceptions, though when I remove this field (it still being present in table) and works the same, just returns null.

What works is this:

$queryBuilder
        ->select(array('card','card.isSpecialCard'))

The "isSpecialCard" field is the one that's not being bound to select, so I have to custom-select it out of table and THEN it's loaded via select. Also, it's being loaded in another level of array, NEXT TO THE OBJECT OF CARD not IN THE OBJECT, though the object still has that field AND IT HAS VALUE AS IF IT WAS SELECTED.

I am using Symfony 2.1.

解决方案

You should not make the changes manually, but let the ORM driver do them for you. Use these two commands to update the Entity and your database accordingly:

php app/console doctrine:generate:entities Namespace:Card
php app/console doctrine:schema:update --force

这篇关于Symfony2 YAML实体字段未绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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