具有“可选”必填字段的实体。 取决于UI中使用的表单

问题描述:

I have a Company entity in Doctrine and Symfony 2. In my Entity I have declared fields such as Name, Street, Zip, City, Country etc... as required using the Doctrine annotations.

Now, in the User Experience I would like people to be able to add a new Company in a quick way.

For example, when adding a project and the user needs to add new Company that's not yet in the database, I'd like for them to enter the Company Name only and automatically create a task in their dashboard, "COMPLETE COMPANY X".

In that way, they can focus on their primary task, which is adding a new project and fill in the required company fields later. But the good thing is that the Company now has an ID and record in the DB and I can use it to link to projects etc...

How would you tackle this problem? In my current setup the required fields are set in the Model and so the database fields are set to NOT NULL.

Should I create a class LightCompany with only required attribute Name and then a class ExtendedCompany which extends LightCompany with all the required fields?

Is there a better way?

我在Doctrine和Symfony 2中有一个公司实体。 在我的实体中我已经声明了诸如Name,Street之类的字段 ,Zip,City,Country等...根据需要使用Doctrine注释。 p>

现在,在用户体验中,我希望人们能够快速添加新公司 。 p>

例如,在添加项目并且用户需要添加尚未包含在数据库中的新公司时,我希望他们只输入公司名称并自动创建任务 在他们的仪表板中,“COMPLETE COMPANY X”。 p>

通过这种方式,他们可以专注于他们的主要任务,即添加新项目并在以后填写所需的公司字段。 但好处是公司现在在数据库中有ID和记录,我可以用它来链接到项目等... p>

您如何解决这个问题? 在我当前的设置中,必需的字段在模型中设置,因此数据库字段设置为NOT NULL。 p>

我应该创建一个只有必需属性Name的类LightCompany,然后创建一个类ExtendedCompany 哪个扩展LightCompany包含所有必填字段? p>

有更好的方法吗? p> div>

You can set form validation groups based on submitted data. See here for more info.