Symfony:加载固定数据且必填字段为空?
我注意到,即使我们没有在 .yml 文件中指定表的某些必需字段,propel 也会将夹具数据加载到数据库中。
这背后的原因是什么?更容易开发等等?
架构:
jobeet_job:
id: ~
category_id: { type: integer, foreignTable: jobeet_category, foreignReference: id, required: true }
type: { type: varchar(255) }
company: { type: varchar(255), required: true }
logo: { type: varchar(255) }
url: { type: varchar(255) }
position: { type: varchar(255), required: true }
location: { type: varchar(255), required: true }
description: { type: longvarchar(255), required: true }
how_to_apply: { type: longvarchar(255), required: true }
token: { type: varchar(255), required: true, index: unique }
is_public: { type: boolean, required: true, default: 1 }
is_activated: { type: boolean, required: true, default: 0 }
email: { type: varchar(255), required: true }
expires_at: { type: timestamp, required: true }
created_at: ~
updated_at: ~
因此,expires_at 是必需的:true。
数据:
expired_job:
category_id: design
company: Extreme sensio
position: Web Designer
location: Paris, France
description: |
Lorem ipsum dolor sit amet.
how_to_apply: |
Send your resume to fabien.potencier at sensio.com.
is_public: true
is_activated: true
token: job_expired
所以,没有任何地方设置expires_at字段。
但我可以运行
symfony propel:data load 任务。
I noticed that propel loads the fixture data into the database, even though we didnt specify some of the required fields of the table inside the .yml files.
What are the reasons behind this? Easier development, etc.?
Schema:
jobeet_job:
id: ~
category_id: { type: integer, foreignTable: jobeet_category, foreignReference: id, required: true }
type: { type: varchar(255) }
company: { type: varchar(255), required: true }
logo: { type: varchar(255) }
url: { type: varchar(255) }
position: { type: varchar(255), required: true }
location: { type: varchar(255), required: true }
description: { type: longvarchar(255), required: true }
how_to_apply: { type: longvarchar(255), required: true }
token: { type: varchar(255), required: true, index: unique }
is_public: { type: boolean, required: true, default: 1 }
is_activated: { type: boolean, required: true, default: 0 }
email: { type: varchar(255), required: true }
expires_at: { type: timestamp, required: true }
created_at: ~
updated_at: ~
So, expires_at is required: true.
Data:
expired_job:
category_id: design
company: Extreme sensio
position: Web Designer
location: Paris, France
description: |
Lorem ipsum dolor sit amet.
how_to_apply: |
Send your resume to fabien.potencier at sensio.com.
is_public: true
is_activated: true
token: job_expired
So, nowhere is the expires_at field set.
Yet I am able to run
symfony propel:data load task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此链接 http://dev.mysql.com/doc/refman/5.0 /en/timestamp.html 解释了 MySQL 中 TIMESTAMP 类型的默认值(假设您使用 MySQL)。
This link http://dev.mysql.com/doc/refman/5.0/en/timestamp.html explains the defaults for the TIMESTAMP type in MySQL (im assuming your using MySQL).
在您的另一个问题中,您引用了 JobeetJob 类的 save 方法。您可以看到,除非之前手动设置,否则
expires_at
会在那里设置 - 因此填写必填字段,所以一切都很好。In another question of yours you quote the save method of the JobeetJob class. You can see there that the
expires_at
gets set there unless set manually before - therefore filling the required field, so all is good.