Mirage
Mirage

Reputation: 31548

How does Doctrine generate:entities create getters and setter in symfony

I have class User likr this

class user implements UserInterface {

protected id ,
protected username;

Then i have

class student extends user {


protected id ,
protected rollno;

Now when i run this

php app/console doctrine:generate:entities myBundle

Then propery username gets inserted in class student.

I want to know that is this ok or its error. Because then whats the use of extending from base class if my lass is going to be populated with all stuff

Upvotes: 0

Views: 3258

Answers (2)

DonCallisto
DonCallisto

Reputation: 29912

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.

Upvotes: 1

Inoryy
Inoryy

Reputation: 8425

Yeah, that's probably not an error, although I agree it can be annoying.

To see how exactly are they generated you can look into the command class.

Upvotes: 0

Related Questions