-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
scope_changed?
problem with acts_as_paranoid
#158
Comments
Hi @mtomov! I've had issues with combining http://illuminatedcomputing.com/posts/2014/12/acts_as_list-with-soft-delete/ Basically I force |
👍 Good solution. Thank you! |
Indeed, and setting the scope as a string actually bypasses the |
That's how the code looks to me @brendon ! One thing I've noticed about |
I tend to be quite explicit and not rely on |
Looking at this again, we're expecting the scope attribute values to be the same for all items within a scope. Therefore you can't use a field like The alternative as I think you've already alluded to is to manually define the scope method to take into account wether the item is deleted or not (rather than when it was deleted). There's no problem with this; that's why it's possible to override def scope_condition
['notice_area_id = ? AND ? >= CURDATE()', notice_area_id, end_date.to_s(:db)]
end
# A custom acts_as_list scope requires a custom scoped_changed? method
def scope_changed?
changed.include?('notice_area_id') ||
changed.include?('end_date') && (
changes['end_date'][0] >= Time.zone.now.beginning_of_day &&
changes['end_date'][1] < Time.zone.now.beginning_of_day ||
changes['end_date'][1] >= Time.zone.now.beginning_of_day &&
changes['end_date'][0] < Time.zone.now.beginning_of_day
)
end I'll close this for now. |
Hello,
Having both
acts_as_list
andacts_as_paranoid
on a model withacts_as_list scope: [:taxon_id, :deleted_at]
.. when I call
destroy
on an element from a list, I get a gap in the list of items instead of having the items below the deleted ones go a position up.Here is the source of the problem:
If you pay attention to the last but one line
"spree_suites_taxons"."deleted_at" = '2015-03-09 12:48:55.344271'
, you will notice how acts as lists'sdecrement_positions_on_lower_items
is picking up the deleted_at scope from the previous query.I think that all is happening in
list.rb#check_scope
, becauseswap_changed_attributes
is looking for changes for both scopes:Any suggestions? Thank you!
The text was updated successfully, but these errors were encountered: