Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing custom methods #148

Closed
wants to merge 1 commit into from
Closed

Allow passing custom methods #148

wants to merge 1 commit into from

Conversation

sebastian-palma
Copy link

@sebastian-palma sebastian-palma commented Jun 6, 2020

Allows passing custom method name that can be interpolated for creating the dump, e.g find_or_create_by:

Movie.all
# [#<Movie:0x00007f89f799f9e8 id: 1, name: "Machuca", status: nil, created_at: Sat, 06 Jun 2020 20:45:27 UTC +00:00, updated_at: Sat, 06 Jun 2020 20:45:27 UTC +00:00>,
   #<Movie:0x00007f89f799f920 id: 2, name: "Burned after reading", status: nil, created_at: Sat, 06 Jun 2020 20:45:39 UTC +00:00, updated_at: Sat, 06 Jun 2020 20:45:39 UTC +00:00>]

SeedDump.dump(Movie, method: :find_or_create_by)
   (0.4ms)  SELECT COUNT(*) FROM "movies"
   (0.3ms)  SELECT COUNT(*) FROM "movies"
  Movie Load (0.3ms)  SELECT "movies".* FROM "movies" LIMIT $1 OFFSET $2  [["LIMIT", 2], ["OFFSET", 0]]
# "Movie.find_or_create_by([\n  {name: \"Machuca\", status: nil},\n  {name: \"Burned after reading\", status: nil}\n])\n"

or find_or_create_by! or create_or_find_by or whatever you want.

@sebastian-palma sebastian-palma deleted the add-method-option branch March 21, 2023 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant