Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

php - Symfony2 YAML Entity field not being bound

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...