简体   繁体   English

DBIx :: Class查找或创建对象

[英]DBIx::Class Find or Create objects

I'm using DBIx::Class to model the following: 我正在使用DBIx :: Class建模以下内容:

A Recipe with many Tags . 有许多TagsRecipe The Tag is shared with other Recipe objects. Tag与其他Recipe对象共享。

While creating a Recipe object I want to create a set of Tag objects and associate them with the newly created Recipe object. 创建Recipe对象时,我想创建一组Tag对象,并将它们与新创建的Recipe对象相关联。 (The user enters a list of tags and I only have the name of the tag to go with) (用户输入标签列表,而我只有要使用的标签名称)

For the Tags I could iterate over the list and find one that matches the user entered name or create a new object manually. 对于标签,我可以遍历该列表并找到与用户输入名称匹配的标签,或者手动创建一个新对象。

I couldn't find a documented findOrCreate type method in DBIx::Class. 我在DBIx :: Class中找不到记录的findOrCreate类型方法。 Any suggestions ? 有什么建议么 ?

如果您有名称的键,则可以使用find_or_create

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM