0

我有类用户喜欢这个

class user implements UserInterface {

protected id ,
protected username;

然后我有

class student extends user {


protected id ,
protected rollno;

现在当我运行这个

php app/console doctrine:generate:entities myBundle

然后将属性用户名插入班级学生。

我想知道这是可以的还是它的错误。因为如果我的小姑娘要装满所有东西,那么从基类扩展有什么用

4

2 回答 2

1

This isn't an error.
Symfony threats all classes as entities and if you're "mapping" them with doctrine you'll create the corrisponding tables onto database.
Now inheritance have to be taken into account: every "field" (property) into parent classe, will be extended or inherited by child.
So is perfectly clear that the corresponding parent field will be created into database.

To me the best way for solve this is to create a parent class and to migrate all commons (fields,methods and so on...) into it.
Then, you'll extend that new parent calss into user with specific fields (in that case username) aswell into student with student's specific fields.

于 2012-07-13T09:10:46.827 回答
0

是的,这可能不是错误,尽管我同意这可能很烦人。

要查看它们是如何生成的,您可以查看命令类

于 2012-07-13T07:32:51.787 回答