简体   繁体   English

Symfony3,创建实体而不映射所有表字段

[英]Symfony3, creating entity without mapping all table fields

I have a database table which has a lot of fields. 我有一个包含很多字段的数据库表。 I want to create an Entity which maps only to few of those fields. 我想创建一个仅映射到其中几个字段的实体。
Is there a practical way to achieve that? 是否有实现此目标的实用方法?

When I try to make an entity and mapping it via annotations, the doctrine:schema:validate command says that the entity is not in sync, and is right. 当我尝试制作一个实体并通过注释将其映射时, doctrine:schema:validate命令会说该实体不是同步的,并且是正确的。
When I try to make a doctrine:schema:update it automatically drops all the fields that the entity doesn't have. 当我尝试创建一个doctrine:schema:update它会自动删除该实体没有的所有字段。 I want that the schema update command updates only the fields written in my entity class. 我希望模式更新命令仅更新在我的实体类中编写的字段。

With Doctrine ORM you map your database table to a PHP class and a row from that table is mapped to an instance of the entity class. 使用Doctrine ORM,您可以将数据库表映射到PHP类,并将该表中的行映射到实体类的实例。 So i am pretty sure that you have to map all your fields. 因此,我很确定您必须映射所有字段。 Otherwise if you dont want to - user ActiveRecord, it is possible there. 否则,如果您不想-用户ActiveRecord,则可以在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM