"Cool" and mostly crazy hotfix for acts_as_paranoid (pls read as core dev)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

"Cool" and mostly crazy hotfix for acts_as_paranoid (pls read as core dev)

Manuel Korfmann

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3b4e3ae7-ff53-461e-9b49-9a8189d66909%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: "Cool" and mostly crazy hotfix for acts_as_paranoid (pls read as core dev)

Manuel Korfmann
Refinements didn’t work when tested properly, so I ended up with this construct

```ruby
def create
Banal::Brainstorm.class_eval do
default_scope lambda { with_deleted }
end

@comment = Comment.new(comment_params)

@comment.save!
redirect_to banal_brainstorms_path

Banal::Brainstorm.class_eval do
default_scope lambda { without_deleted }
end
end
```

On 19. Sep 2019, at 13:02, Manuel Korfmann <[hidden email]> wrote:


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3b4e3ae7-ff53-461e-9b49-9a8189d66909%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CF534AA3-07ED-4BEA-B256-D76400531FCB%40korfmann.info.
Reply | Threaded
Open this post in threaded view
|

Re: "Cool" and mostly crazy hotfix for acts_as_paranoid (pls read as core dev)

Manuel Korfmann
Furtherly refined:

```
def create
ActiveRecord::Base.transaction do
Banal::Brainstorm.class_eval do
default_scope lambda { with_deleted }
end

@comment = Comment.new(comment_params)

@comment.save!
redirect_to banal_brainstorms_path

Banal::Brainstorm.class_eval do
default_scope lambda { where id: (unscoped.pluck(:id) - only_deleted.pluck(:id)) }
end
end
end
```

On 19. Sep 2019, at 13:31, Manuel Korfmann <[hidden email]> wrote:

Refinements didn’t work when tested properly, so I ended up with this construct

```ruby
def create
Banal::Brainstorm.class_eval do
default_scope lambda { with_deleted }
end

@comment = Comment.new(comment_params)

@comment.save!
redirect_to banal_brainstorms_path

Banal::Brainstorm.class_eval do
default_scope lambda { without_deleted }
end
end
```

On 19. Sep 2019, at 13:02, Manuel Korfmann <[hidden email]> wrote:


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3b4e3ae7-ff53-461e-9b49-9a8189d66909%40googlegroups.com.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/B07293EA-F687-407D-8B79-67DF929D9F90%40korfmann.info.