Been refactoring my code today and indeed found a lot of places where I could use that in combination with `find_or_create` or `update_or_create`, which comes especially useful when you have something like:
campaign = Models::Campaign.update_or_create(find_cond) { ... } MailCampaign.perform_async(campaign.id) if campaign.just_created? A reason why I can't put my code inside the &block is because if it's create we don't have model.id there yet, so I can't really do much with the model which I can't reference and it doesn't exist yet in the database. Same goes for find_or_create, so maybe it could find a home in these plugins - a way to know which method was actually triggered find (update) or create? On Thursday, December 30, 2021 at 11:01:35 PM UTC+2 Jeremy Evans wrote: > On Thu, Dec 30, 2021 at 12:51 PM tr...@upserver24.com < > tr...@upserver24.com> wrote: > >> The use case is to know if current instance of the model was created, we >> pass model instance to many services which sometimes need to run additional >> actions if new record is just created, we can't have in after_create >> callback because model doesn't know about the services also sometimes it's >> too early to call it from a model callback because other information might >> be needed. > > > I guess such usage is fine for your particular needs, but it doesn't sound > like something I'd want to include with Sequel. You should consider > shipping it as an external gem, and send a PR to link to the gem from > Sequel's website (edit www/pages/plugins.erb). > > Thanks, > Jeremy > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/e07c111b-c0bf-45bd-a817-2733133a3b6bn%40googlegroups.com.