Sandeep Chayapathi Sandeep Chayapathi - 21 days ago 6
Perl Question

DBIx::Class Find or Create objects

I'm using DBIx::Class to model the following:

A

Recipe
with many
Tags
. The
Tag
is shared with other
Recipe
objects.

While creating a
Recipe
object I want to create a set of
Tag
objects and associate them with the newly created
Recipe
object. (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. Any suggestions ?

Answer

If you have a key on the name you can use find_or_create.