be090129 / substruct

Automatically exported from code.google.com/p/substruct
0 stars 0 forks source link

it is expected to show the products tagged with this tag. but list all the products . (the newest version :substruct_rel_1-0-a3.tar.gz) #89

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. go to http://localhost:3000/admin/tags/list,  create some tags
2.  http://localhost:3000/admin/products/new, create some products, each 
product has only 
one different tag. 
3. go to public site, I find that for each tag, it will list all the products.  
it is a big error.

What is the expected output? What do you see instead?
for each tag, it is expected to show the products tagged with this tag.  but 
list all the products .

What version of the product are you using? On what operating system?
the newest version:substruct_rel_1-0-a3.tar.gz,    in my macbook,  leopord 
10.5,  mysql 5.0,  

Please provide any additional information below.
at last, I find this code cause this problem 

in the product.rb , find_by_tags method:

                    sql =  "SELECT * "
                    sql << "FROM items "
                    sql << "JOIN products_tags on items.id = products_tags.product_id "
                    sql << "WHERE products_tags.tag_id IN (#{tag_ids.join(",")}) "
                    sql << "AND #{CONDITIONS_AVAILABLE}" if find_available==true
                    sql << "GROUP BY items.id HAVING COUNT(*)=#{tag_ids.length} "
                    sql << "ORDER BY #{order_by};"
                    find_by_sql(sql)

if you delete :
sql << "AND #{CONDITIONS_AVAILABLE}" if find_available==true
                    sql << "GROUP BY items.id HAVING COUNT(*)=#{tag_ids.length} "
                    sql << "ORDER BY #{order_by};"
it works ok, 
but mysql knowleage is not very good, and because there is some problem with 
the subnav_tags(if you tag the product with a tag and this tag' s child, and if 
click the child tag, list 
two product, and they are the same)

so , I fix like this with my poor rails knowleage:

if tag_ids.size == 1
            child_tags = Tag.find(tag_ids[0]).children.collect {|x| x.id}

            tag_ids = tag_ids + child_tags
        elsif tag_ids.size == 2
            tag_ids.shift
        end
        sql = "SELECT DISTINCT *  FROM items  as li inner join products_tags as pt on li.id = 
pt.product_id WHERE pt.tag_id IN (#{tag_ids.join(",")})"
 find_by_sql(sql)

Original issue reported on code.google.com by liuyin...@gmail.com on 31 May 2008 at 11:24

GoogleCodeExporter commented 8 years ago
I cannot reproduce this.

Created 5 products. Created 5 top level tags (you didn't specified which kind of
tags). Each product was associated with four tags. In each tag, appears four 
products.

The find_by_tags method appears fine to me, is a method where you pass an array 
of
tag ids and it will return the products that are in ALL of them. this is the 
reason
of the group by clause comparing the count with the number of tags passed.

Is you trying to associate things any different than that? Like associating 
products
with child tags without marking its top level tags too?

Original comment by edmundo...@gmail.com on 1 Jun 2008 at 9:26

GoogleCodeExporter commented 8 years ago
Yes, I associate products  with child tags without marking its top level tags 
too.

and I am using chinese language. pls see if there is some language supporting 
problem

Original comment by liuyin...@gmail.com on 5 Jun 2008 at 8:24

GoogleCodeExporter commented 8 years ago
I cannot reproduce it in any way. But I don't have a Mac and don't use my OS in 
chinese.

I yet don't know how did you created and associated your products and tags 
(simply
saying that you did in another way is not enough), normally is more usefull 
pick up a
clean system and describe a scenario with more details.
In any situation it works? 

You can take a look at the MySQL products_tags table and see if the relations 
are right.

The system have automate tests that test relations between products and tags, 
you can
try it:
$ ruby 
./vendor/plugins/substruct/test/functional/admin/products_controller_test.rb

It shoud show something like that.

Loaded suite 
./vendor/plugins/substruct/test/functional/admin/products_controller_test
Started
...................
Finished in 7.082522 seconds.

19 tests, 139 assertions, 0 failures, 0 errors

Original comment by edmundo...@gmail.com on 7 Jun 2008 at 1:43

GoogleCodeExporter commented 8 years ago
I'm getting this same error. It started when I switched from using mysql 4 to 
mysql5.
The reason I switched is that I was getting a large number of "Mysql::Error: 
Lost
connection to MySQL server during query" errors.

Original comment by patrickb...@gmail.com on 9 Jun 2008 at 8:32

GoogleCodeExporter commented 8 years ago
So apparently this error happens if you are navigating to a tag that does not 
exist.

Original comment by patrickb...@gmail.com on 9 Jun 2008 at 8:41

GoogleCodeExporter commented 8 years ago
Im using MySQL 5 in Ubuntu (by months) and don't have that problem.

edmundo@toshibau305:~$ dpkg -l | grep mysql-server-
ii  mysql-server-5.0    5.0.45-1ubuntu3.3    MySQL database server binaries

Can you explain how a tag that does not exist can have a link that can be 
clicked in
the menu and make all products appear?

I still cannot reproduce it.

Original comment by edmundo...@gmail.com on 9 Jun 2008 at 9:44

GoogleCodeExporter commented 8 years ago
The MySQL version turned out to have nothing to do with this problem. (The lost
connection problem had to do with the bindings and was resolved by running 
apt-get
install libmysql-ruby1.8)

To answer your question:

A tag that does not exist does not have a link that can be clicked. After I 
switched
from MySQL 4 to 5 I created a new db. Then ran db:bootstrap and migrate. Then 
went
back to the browser and hit reload. It happened to be on 
'store/show_by_tags/tagname'
where tag name no longer exists.

So, if you want to reproduce this error, navigate to
store/show_by_tags/sometagnamethatdoesnotexist. Unless of course you've caught 
this
exception and rerouted.

Original comment by patrickb...@gmail.com on 9 Jun 2008 at 10:15

GoogleCodeExporter commented 8 years ago
No, that's ok.

Thats the point, its a problem with the store controller not handling a non 
existent
tag when using the show_by_tags action. It is a problem, but dont have anything 
to do
with this issue.

For me it raises an ActiveRecord::StatementInvalid exception.

Fixed in issue 96.

The current one, I cannot reproduce.

Original comment by edmundo...@gmail.com on 10 Jun 2008 at 1:47

GoogleCodeExporter commented 8 years ago
Thanks for the info and the patch. Would you like me to delete my comments 
above as
they do not apply to this issue?

Original comment by patrickb...@gmail.com on 10 Jun 2008 at 5:39

GoogleCodeExporter commented 8 years ago
Im not the developer of the project. But I don't think so. When deleted things
changes from wrong to nonsense. If not reproductible this issue will be marked 
as
invlid and closed in the end anyway.

Original comment by edmundo...@gmail.com on 10 Jun 2008 at 6:51

GoogleCodeExporter commented 8 years ago
Good discussion, glad this resolved. Thanks Edmundo again for lending a hand.

Original comment by subim...@gmail.com on 15 Jun 2008 at 7:46