如何使学说不在数据库中保留重复的对象?
我有两种不同类型的对象:行程和位置。
行程有一个起点和目的地,它们都是Location对象。
位置不会指向骑行。
这意味着我在教义上具有多对一的单向关系。
如何使原则确保我的数据库中没有任何重复的 Location 对象?
例如: 如果我创建从明尼苏达州明尼阿波利斯到明尼苏达州曼凯托的 Ride 并保留它们,我现在已在数据库中存储了一个 Ride 和两个 Location 对象。
现在这些都已保留,我将创建另一个从明尼苏达州曼凯托到明尼苏达州新乌尔姆的行程并保留它们。
Doctrine 复制了明尼苏达州曼凯托的位置。
学说是否具有此功能,或者我有责任检查我是否正在创建重复的对象?
I have two different kinds of objects: Ride and Location.
A Ride has an origin and a destination which are Location objects.
Location does not point back to the Ride.
This means I have a many-to-one uni-directional relationship in doctrine.
How can I make doctrine ensure that I don't have any duplicate Location objects in my database?
For Example:
If I create a Ride from Minneapolis, MN to Mankato, MN and persist them I now have stored one Ride and two Location objects in my database.
Now that those are persisted, I go to create another Ride from Mankato, MN to New Ulm, MN and persist them.
Doctrine has duplicated the Location Mankato, MN.
Does doctrine have this functionality, or is it my responsibility to check if I am creating duplicate objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否对位置名称(可能是州名称+城市名称)施加唯一约束?
您有责任查看该位置是否已存在。如果是这样,获取它并将其提供给您的 Ride 对象。
Can you put a unique constraint on Location Name (Maybe state name + city name)?
It's your responsibility to see if the location already exists. And if so, fetch it and supply it to your Ride object.