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.

Named `just_created?` because it's an indicator that `after_create` 
callback was called for that instance. 

Agree `save.save` is a bummer going to fix it.

On Thursday, December 30, 2021 at 10:12:14 AM UTC+2 Jeremy Evans wrote:

> On Wed, Dec 29, 2021 at 8:47 AM tr...@upserver24.com <tr...@upserver24.com> 
> wrote:
>
>> Hi,
>>
>> We found this tiny useful plugin that allows to detect if model instance 
>> was just created:
>>
>> ```
>> module Sequel
>>   module Plugins
>>     module JustCreated
>>       module InstanceMethods
>>         def after_create
>>           @just_created = true
>>           super
>>         end
>>
>>         def just_created?
>>           @just_created == true
>>         end
>>       end
>>     end
>>   end
>> end
>> ```
>>
>> I was trying to do it using :dirty plugin but didn't found a way, maybe I 
>> missing something? If not don't you mind if we create PR to include this 
>> plugin into sequel?
>>
>
> I don't think the dirty plugin supports this.  Could you explain the use 
> case for the plugin?  That would help me to better judge whether to include 
> it with Sequel.  Note that even if it isn't included with Sequel, it's easy 
> to ship as a external gem.
>
> The plugin has at least one implementation issue:
>
> Model.new.save.save.just_created? # => true, should be false, assuming you 
> want a object that hasn't been updated
>
> Also, I'm not sure "just_created" is a good name.  After all:
>
> m = Model.create
> sleep(60*60*24)
> m.just_created? # "just" generally implies recently.
>
> 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/f1f30044-5a28-4d17-a97d-5a5bbb0a5f4bn%40googlegroups.com.

Reply via email to