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

Unscope all create or update queries #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

korstiaan
Copy link
Member

We have a default scope on our model, which filters out non published posts. This resulted in WpCache.create_or_update trying to insert the same (unpublished) wp_id multiple times because where(wp_id: wp_id) didn't return this unpublished post.

@Marthyn
Copy link
Member

Marthyn commented Jun 17, 2015

we shouldn't use a default scope anyways i think. And make a published scope and use where needed. Much more descriptive and you dont need to use unscoped.
http://rails-bestpractices.com/posts/2013/06/15/default_scope-is-evil/

@@ -41,7 +41,7 @@ def create_or_update(wp_type, wp_id, preview = false)
# WP API will return a code if the route is incorrect or
# the specified entry is none existant. If so return early.
return if wp_json[0] and invalid_api_responses.include? wp_json[0]["code"]
where(wp_id: wp_id).first_or_initialize.update_wp_cache(wp_json)
unscoped.where(wp_id: wp_id).first_or_initialize.update_wp_cache(wp_json)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should DRY this up a bit 🍶

@dunyakirkali dunyakirkali added this to the V1.1.0 milestone Jun 17, 2015
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.

4 participants