mie
mie

Reputation: 721

Datamapper's first_or_create equivalent in sequel?

Is there a native Sequel way to implement Datamapper's first_or_create method?

Or am I bound to combine selects and inserts?

Upvotes: 1

Views: 1252

Answers (1)

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24617

I think find_or_create should work for you.

Like find but invokes create with given conditions when record does not exist. Unlike find in that the block used in this method is not passed to find, but instead is passed to create only if find does not return an object.

Upvotes: 4

Related Questions