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

Fixed Product.in_taxon to not return duplicates #1962

Closed
wants to merge 2 commits into from
Closed

Fixed Product.in_taxon to not return duplicates #1962

wants to merge 2 commits into from

Conversation

laurens
Copy link
Contributor

@laurens laurens commented Sep 13, 2012

When a product is assigned to a parent taxon and that parent’s child taxon, Product.in_taxon(taxon)should not return duplicate records.

radar pushed a commit that referenced this pull request Sep 17, 2012
radar pushed a commit that referenced this pull request Sep 17, 2012
@radar
Copy link
Contributor

radar commented Sep 17, 2012

This commit causes a build to break: http://travis-ci.org/#!/spree/spree/jobs/2483894. I will investigate.

end

it "calling Product.in_taxon should not return duplicate records" do
Spree::Product.in_taxon(@taxon).length.should == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

You're using length here because count returned an incorrect value, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With count, ActiveRecord performs the counting on the database using a "SELECT DISTINCT COUNT(*) FROM "spree_products" … which leads to a wrong result

@radar
Copy link
Contributor

radar commented Sep 17, 2012

I am going to revert this commit due to the broken build. I cannot figure out how to fix the broken spec.

@laurens
Copy link
Contributor Author

laurens commented Sep 21, 2012

I see, .uniq messes up the query of the price filter since the DISTINCT is added to the query in a wrong way.

Do you think, using .select("DISTINCT(spree_products.id), spree_products.*") instead of .uniq would be an alternative?

@radar radar closed this in 8a303e1 Oct 18, 2012
radar added a commit that referenced this pull request Oct 18, 2012
Fixes #1917

Fixes #1974

Fixes #1962

Conflicts:

	core/app/models/spree/product/scopes.rb
	core/spec/models/product/scopes_spec.rb
radar added a commit that referenced this pull request Oct 18, 2012
Fixes #1917

Fixes #1974

Fixes #1962

Conflicts:

	core/app/models/spree/product/scopes.rb
	core/spec/models/product/scopes_spec.rb
@radar
Copy link
Contributor

radar commented Oct 18, 2012

Yes, that appears to work. I've merged this PR to master, 1-2-stable and 1-1-stable. Thanks!

@laurens laurens deleted the fix_for_in_taxon branch January 8, 2013 22:00
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.

None yet

2 participants